我有一个简单的乒乓球游戏,当我通过按退出键暂停游戏时,用户仍然可以左右移动球拍。该游戏是一款涉及触摸的手机游戏。当游戏暂停时,我将如何确保桨板不可移动?
如果这有帮助,这是我的桨的代码:
private var ray : Ray;
private var hit : RaycastHit;
function Start () {
}
function Update () {
if(Input.GetMouseButton(0)){
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit)){
transform.position.x = hit.point.x;
}
}
}
这是我的暂停脚本:
var gamePaused : boolean = false;
var back : Texture2D;
var GUIskin:GUISkin;
var ClickSound:AudioClip;
function Start(){
Time.timeScale=1;
gamePaused = false;
gameObject.GetComponent(PauseMenu).enabled = false;
}
function OnGUI(){
GUI.skin = GUIskin;
GUI.Box (Rect (Screen.width - 550,Screen.height - 700,400,200), back);
if(GUI.Button(new Rect(Screen.width - 510,Screen.height - 615,120,80), "Main Menu")) {
Application.LoadLevel("Menu");
audio.PlayOneShot(ClickSound);
}
if(GUI.Button(new Rect(Screen.width - 310,Screen.height - 615,120,80), "Quit")) {
audio.PlayOneShot(ClickSound);
Application.Quit();
}
}
这也是我的暂停控制器:
private var gamePaused : boolean = false;
function Update () {
if(Input.GetKeyDown(KeyCode.Escape)){
if(gamePaused){
Time.timeScale=1;
gamePaused = false;
gameObject.GetComponent(PauseMenu).enabled = false;
}
else{
Time.timeScale = 0;
gamePaused = true;
gameObject.GetComponent(PauseMenu).enabled = true;
}
}
}