- Home /
Pause Menu - Loading & Quitting
I'm making a pause menu. One of the buttons quits the game and goes to the main menu. The problem is, when I load another level, the game is still paused, even though it's a different level. Here's the code.
The Pauser
functon Update() {
if(Input.GetKeyUp("p")){
if(!paused){
Time.timeScale = 0;
paused=true;
}else{
Time.timeScale = 1;
paused=false;
}
}
}
The GUI Menu Button
function OnGUI(){
if(paused) {
GUI.backgroundColor = Color.white;
GUI.contentColor = Color.white;
GUI.Box(Rect(375,200,Screen.width/2,Screen.height/2), ".");
}
if(paused && GUI.Button(Rect(600,300,300,40), "Main Menu")){
Application.LoadLevel (" Main Menu");
paused = false;
}
I thought that by making paused false:
paused = false;
It would work, but still, when I loaded other levels, it was still paused. I'm not sure what to do.
Answer by syclamoth · Sep 23, 2011 at 01:57 AM
Put a 'Depauser' script in your new level, which sets the timeScale back to 1 during the 'OnLevelWasLoaded' callback. This way, whenever the level gets loaded, the game automatically unpauses!
It doesn't work because it's in a whole new scene. This is the "Depauser" script.
function OnLevelWasLoaded () {
var isPaused = Starship.paused;
if(isPaused){
Time.timeScale = 1;
}
}
Your answer
Follow this Question
Related Questions
Halt function midway until player presses 'OK' then continue 1 Answer
Look like a Website Menue! 1 Answer
GUI Buttons not working after scene transition 0 Answers
Paused Menu backdrop 1 Answer
Close my GUI button by repressing the same Hot-key. 3 Answers