Pause Menu Won't Disappear

So I’m writing a pause menu for my game; A very simple one to say the least. I’m having trouble with making the pause menu disappear after “loading last checkpoint”. I’ve tried a few different solutions with no avail. Currently when I press the button the last checkpoint is reloaded, but the pause menu doesn’t disappear. I can’t close it either by hitting the “P” key. I’ve tried debugging to see what’s happening, and for some reason I have the variable “isPaused” printing as true and false. I’m pretty sure that’s my problem but I have no idea how to fix it. Anything suggestions would be appreciated. Thank you

Here’s the code for the script I’m using

#pragma strict
private var buttonWidth: int = 150;
private var buttonHeight: int = 55;
var isPaused : boolean;
var pressed: boolean;
function Start () {
isPaused = false;
}

function Update () {
	if(Input.GetKeyDown(KeyCode.P)){
		if(!isPaused){
			Time.timeScale = 0;
			isPaused = true;
		}else if(isPaused){
			Time.timeScale = 1;
			isPaused = false;
		}

	}
}

function OnGUI(){

	if(isPaused){
		GUI.Box(new Rect(0,0, Screen.width, Screen.height), 'Paused');
		if(GUI.Button(new Rect(Screen.width/2 - buttonWidth/2, Screen.height - 150, buttonWidth, buttonHeight), "Save and Quit")){
			GetComponent(CheckpointSave).save();
			Application.LoadLevel(0);
		}
		if(GUI.Button(new Rect(Screen.width/2 - buttonWidth/2, Screen.height - 300, buttonWidth, buttonHeight), "Restart Level")){
			isPaused = false;
			Application.LoadLevel(Application.loadedLevel);
		}
		if(GUI.Button(new Rect(Screen.width/2 - buttonWidth/2, Screen.height - 450, buttonWidth, buttonHeight), "Reload Last Checkpoint")){
			GetComponent(CheckpointLoad).loadLastCheckpoint();
			isPaused = false;
		}
	}
	print("Paused? " + isPaused);
}

That was it! I had a second player inside of the scene (There's two playable characters at the same time in the game) I just removed it from one of them and it works perfectly now. Thank you!

2 Answers

2

function Update () {
if(Input.GetKeyDown(KeyCode.P)){
if(!isPaused)
Time.timeScale = 0;
else if(isPaused)
Time.timeScale = 1;
isPaused = !isPaused;

    }
}

try this :slight_smile:

You would not have the script on two objects? You say it prints as true and false, look in the console what object calls the print. Also, you can add:

print("Paused? " + isPaused+" "+gameObject.name);

At least, if it does not fix it will narrow the possibilties…