- Home /
[Solved] Restarting scene not automatically playing (pause button?)
When starting the game up, and clicking the start game from the title menu, everything works just fine. Its when from the pause button you go back to the menu, and click start game again that it requires you to push the pause button for the game to resume. Unsure how to get it to start up automatically, like it does the first time the scene is loaded.
Order: 1) Clicks start game
2)Goes to top right button, pause.
Here is some of the code:
public static bool paused = false;
public void pause()
{
paused = !paused;
Time.timeScale = $$anonymous$$athf.Approximately(Time.timeScale, 0.0f) ? 1.0f : 0.0f;
leftstick.SetActive(!paused);
rightstick.SetActive(!paused);
options.SetActive(paused);
}
I was wondering if it may be related that the level manager script that handles the scenes may require changing the paused bool before switching scenes?
Answer by Tobychappell · May 23, 2018 at 09:35 PM
Changed my answer after noticing your comment with the code that you are using.
This fix would depend on what is calling this method and why.
For a quick fix you could introduce an optional nullable Boolean parameter in the method so that when it is true it will change the pause state to paused and flase to unpaused.
// Booleans initialise as false,
// Making it a property in this way restricts access to this. This will help prevent something else messing with the expected outcome of pause() when it is used.
public static bool IsPaused { get; private set; }
public void pause(bool? overridePause = null)
{
if (overridePause.HasValue)
{
IsPaused = overridePause.Value;
}
else
{
IsPaused = !IsPaused;
}
// removed "Mathf.Approximately(Time.timeScale, 0.0f)" as it seems you want the timescale to be 1 or 0 based on the value of 'IsPaused' not the value of the timescale itself.
Time.timeScale = IsPaused ? 0 : 1;
leftstick.SetActive(!IsPaused);
rightstick.SetActive(!IsPaused);
options.SetActive(IsPaused);
}
For normal toggling of Pausing:
pause();
For explicitly pausing the game:
pause(true);
For explicitly un-pausing the game:
pause(false);
Ended up really cleaning up my code and working finally. Thank you so much! It worked by changing the timescale at the start of the scene to 1 which I didn't think of before.
Answer by 3kWikiGames · May 23, 2018 at 09:02 PM
3)Goes back to the Title Screen
4) After starting game up again, it shows this screen but paused, requiring another push of the pause button for the game to resume correctly
Your answer

Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
HyperCasual mobil control 0 Answers
Pasue Game and then Ask for input to unpasue 0 Answers
Character Controller Initial Problem With Mobile 0 Answers
Xbox 360 Control GUI problem 0 Answers