- Home /
Question by
pixiefury15 · Nov 22, 2012 at 07:30 AM ·
menupauseongui
if statement will only execute once
This is code at the end of my Update() function. It calls an in game pause menu.
if (Input.GetKeyDown(KeyCode.Escape)){
Time.timeScale = 0;
script = GameObject.Find("pauseObject");
var pauseScript = script.GetComponent("pause");
pauseScript.enabled=true;
script = GameObject.Find("level");
var levelScript = script.GetComponent("Level");
levelScript.enabled=false;
}
This is the code for resuming the game in pause.js code.
this.enabled = false;
function pauseMenu() {
//resume game button
if(GUI.Button(Rect(55, 150, 180, 40), "Resume Game")) {
//Debug.Log("resume");
this.enabled = false;
Time.timeScale = 1;
}
//layout end
GUI.EndGroup();
}
function OnGUI () {
if (this.enabled){
pauseMenu();
}
}
The code works perfectly the first time I pause and reenter game play. But if I try to pause again (by pushing Escape), nothing happens. Anyone have any idea why this is?
Comment
Best Answer
Answer by pixiefury15 · Nov 22, 2012 at 05:55 AM
I got it working. I had to take out
`script = GameObject.Find("level");
var levelScript = script.GetComponent("Level");
levelScript.enabled=false;`
from the Update() code. levelScript was being set to false without being set to true again. Turns out these lines of code are unneccessary anyway.