- Home /
Question by
kbresciani117 · Jan 16, 2015 at 11:40 PM ·
physicsbuttonpausepause menupause game
Game stays paused after Restart.
Hi whenever I press the restart button The game stays paused and I have press P twice for it to unpause. This also happens after I click the Main Menu button after I go to the Main Menu and press play Can someone help with this problem?
static var PauseGame : boolean = false;
private var PauseMenu : Rect = Rect((Screen.width*.5) + -100 ,(Screen.height*.25), Screen.width/4, Screen.height/4);
var level : String;
function Awake ()
{
PauseGame = false;
}
function Update ()
{
if (Input.GetKeyDown ("p"))
{
PauseGame = !PauseGame;
if (PauseGame == true)
{
Time.timeScale = 0;
PauseGame = true;
}
if (PauseGame == false)
{
Time.timeScale = 1;
PauseGame = false;
}
}
}
function OnGUI()
{
if (PauseGame == true)
{
GUI.Window (0,PauseMenu, TheMainMenu, "Pause Menu");
}
}
function TheMainMenu ()
{
if(GUILayout.Button("Main Menu"))
{
Application.LoadLevel("MainMenu");
PauseGame = false;
}
if(GUILayout.Button("Restart"))
{
PauseGame = false;
Application.LoadLevel(level);
}
if(GUILayout.Button("Quit"))
{
Application.Quit();
}
}
Comment
Answer by UziMonkey · Jan 17, 2015 at 12:12 AM
You aren't actually unpausing the game on awake, you're just setting the paused flag. Set timescale in the awake functon and it should work.
function Awake ()
{
PauseGame = false;
Time.timescale = 1;
}
Alternatively I think they could just set the timeScale to 1 in the The$$anonymous$$ain$$anonymous$$enu function if the player presses the main menu or restart buttons.
The reason I suggest doing it this way is so that the game doesn't end up with a time scale of 0 on the main menu.