- Home /
Game Loop, Update(), and Pause
Before using Unity, my game loop looks like
void DoGameLoop()
{
if ( InGameState )
Game.Update();
else if ( InPauseMenu )
PauseMenu.Update(); //Animation or something
////else blablabla...
}
or
void DoGameLoop()
{
if ( IsPause ) return;
Game.Update();
AnimationSystem.Update();
//blablabla...
}
But in Unity, it makes game loop for us. I use Update() in ALMOST every Monobehavior.
It seems the easiest way now to pause the game is Time.timeScale = 0 But if I do this, I have to use Time.realtimefromstartup for those shouldn't stop. It just makes me feel the bad smell in code.
Seems the old thing is a good choice. However, if NOT using Time.timeScale = 0, pause unity animations and Invoke() will be some trouble.
Like GC, it exist, but you shouldn't use it too much. I want to ask, how about Update()? Do I rely too much on Update()? How do you use Update() or how do you build your game loop?
Answer by Morgan · May 16, 2015 at 03:05 AM
Update() is great for just about anything! I doubt you're overusing it.
If you want something to continue during Time.timeScale = 0, you can use Time.unscaledDeltaTime instead of Time.deltaTime.
Update() continues to run when timeScale is 0, but you have to use a different delta in animations that should not pause.
http://docs.unity3d.com/462/Documentation/ScriptReference/Time-unscaledDeltaTime.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613195719im_/https://answers.unity.com/themes/thub/images/avi.jpg)