- Home /
Other
Problem with Time.timeScale
Hi, so I am making a simple game, but there is a problem. When the player gets to 0 lives, the game slows down and shows game over screen. Then, there is a button to restart and play transition. But, when it starts playing transition, the transition is slowed down too. I tried to bring back Time.timeScale to 1, but it doesn't seem to work. Please help me!
And here is the code:
public void RestartGame()
{
anim.Play("TransitionStart", 0);
StartCoroutine(WaitBeforeLoading());
}
IEnumerator WaitBeforeLoading()
{
Time.timeScale = 1;
yield return new WaitForSecondsRealtime(2.5f);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
You should add a breakpoint after your timescale assignment to check and make sure that the value is getting set correctly. If it is, I suspect your problem lies elsewhere. Also, you should append 'f' to the end of 1 so you're properly assigning a float number to timescale (Time.timeScale = 1f)
Doesn't seem to work...
Idk, maybe the problem is because I am using unity 2020.1.0f1
So I founded a solution: I made another boolean variable that is true whenever the transition starts and in the update at the if statement that checks is player at 0 lives added && !startedTransition. Now everything works fine :)
Glad you managed to resolve it :) thanks for reporting back.