Time.timeScale is 0 but game not frozen
I'm working on my first Unity game so I'm still getting to grips with all the libraries.
I have two menus and scripts, one for pausing the game using a button and another for finishing the level. The pausing code is the same on both scripts, but only the pause menu script actually pauses the game.
When the player hits the end of the level it should bring up the menu and pause the game using Time.timeScale = 0f. The menu comes up but the game doesn't pause. I am at a loss on what to do and it's probably a silly mistake that I have overlooked. Debug.Log(Time.timeScale) outputs 1s and then 0s after trigger.
void Update () {
if (isPaused) {
Time.timeScale = 0f;
} else {
Time.timeScale = 1f;
}
Debug.Log(Time.timeScale);
}
void OnTriggerEnter2D(Collider2D other)
{
finishMenu.SetActive (true);
isPaused = true;
}
public void FinishLevel()
{
finishMenu.SetActive (false);
isPaused = false;
Application.LoadLevel("TestLevel");
}
As a workaround, I've created a seperate file that specifically toggles the timeScale and just call that from the two menu scripts. I guess something was conflicting.
Your answer
Follow this Question
Related Questions
Wait time after coroutine's wait seconds is complete 0 Answers
How to use time, when timeScale is 0? 2 Answers
why does timescale not work? 2 Answers
Suspension of Physics 1 Answer