No esc when game over.

So I got a nice press esc to pause the game. And you can get out of time (game over)
But when you are game over you can still press esc. I tried something with a noEsc but it didn’t work.

Anyone can help me out?

**My pause script**

var isPaused : boolean = false;

function Update () {
	if(Input.GetKeyDown("escape") && !isPaused){
		Time.timeScale = 0.0;
		isPaused = true;
	}
	else if (Input.GetKeyDown("escape") && isPaused){
		Time.timeScale = 1.0;
		isPaused = false;
	}
}

function OnGUI () {
	if(isPaused){
		GUI.Box (Rect (490,250,300,160), "game menu");
		if(GUI.Button (Rect (590,310,100,20), "restart")){
			//ResetVariables();
			Application.LoadLevel("level9");
			Time.timeScale = 1.0;
			isPaused = false;
		}
		if(GUI.Button (Rect (590,340,100,20), "continue")){
			Time.timeScale = 1.0;
			isPaused = false;
		}
		if(GUI.Button (Rect (590,370,100,20), "back to menu")){
			Application.LoadLevel("menu");
		}
		GUI.Label (Rect (260,280,242,100), "				");
	}
}

@script AddComponentMenu ("GUI/Pause GUI")
//function ResetVariables()
//{
//	gameOver.noEsc = false;
//}



**And my game over script**

var timerValue: float = 5; //You can change this in the inspector.
var myTimer: float;

//var noEsc = false;

//var GuiButtonStyle : GUIStyle;
//var GuiBoxStyle : GUIStyle;

var timerOutput: GUIText;
var timeIsUp = false; 

function Start(){
	Time.timeScale = 1.0;
}

function Awake(){
	myTimer = timerValue;
}

function Update(){
	if(myTimer > 0){
		myTimer -= Time.deltaTime; 
		var seconds: int = myTimer % 60; 
  		var minutes: int = myTimer / 60; 
  		timerOutput.text = minutes + ":" + seconds;
	}	
	if(myTimer <= 0){
		timeIsUp = true;
		Time.timeScale = 0.0;
	}

}

function OnGUI(){
	if(timeIsUp == true){	
		GUI.Box (Rect (490,250,300,160), "Game over"/*, GuiBoxStyle*/);
		if(GUI.Button (Rect (590,310,100,20), "restart"/*, GuiButtonStyle*/)){
			//noEsc = true;
			Application.LoadLevel("level9");
			resetTheVariables();
			myTimer = timerValue;
		}
		if(GUI.Button (Rect (590,340,100,20), "menu"/*, GuiButtonStyle*/)){
			resetTheVariables();
			Application.LoadLevel("menu");
		}
	}
}

@script AddComponentMenu ("GUI/Pause GUI")

function resetTheVariables(){
//	noEsc = false;
}

1 Answer

1

function Update () {
if(Input.GetKeyDown(“escape”) && !noEsc){
Time.timeScale = 0.0;
isPaused = !isPaused;
}
}

your noEsc code should work as long as you add that case to your Input checking. also, I cut down on your redundant code by just setting isPaused = !isPaused. it’s a minor change, but it cuts out an extra case for you