Pause menu in Unity

Daniel Kirwan
3 min readMay 12, 2021

Objective: Created a menu that allows the player to pause the game.

Creating a pause menu in Unity can be as simple as setting the Time.TimeScale = 0f; That’s it and to make the game play again set it back to 1f; Doing this effectively pauses all time based operations including movement, physics and animation. You can also select certain game objects to ignore the time scale so that an animation in the pause menu can continue to run. You can change this in the Animator on a game object.

You set the Update mode of the animator from normal to Unscaled time, this will allow you to continue to run this animation. This is not the way that I am doing it I just thought it would be nice for you to know :)

Like I mentioned above I am setting the TimeScale to 0 and then back to 1. But how do I get the game object to turn off and on repeatedly if everything is paused?

Well I am using a coroutine. The way that you can still use a coroutine when the scale is set to 0 is to use the yield return of WaitForSecondsRealtime. This ignores the timescale similar to the change in the animator above.

I am using a bool that keeps track of whether the game is paused and then while it is true I wait for half a second and the turn the text object on, then wait another half second and turn it back off. This will continue to run as long as the game is paused.
As soon as the player pressing the resume button the bool is turn to false and the coroutine stops.

For the pause menu I needed to add a Text object, a button and the bool mentioned above. In the update method for the UIManager I am checking for if the Escape key is pressed and when it is, the PauseGame method is run.

And that’s it for this article, if you found this interesting please check out my other articles on game development in Unity.

--

--