Pausing a game, and I talk about the functionality, not the pause button itself, is one of the most universal features in games, but I’ve never understood how best to implement “pausing.” To clarify, I’m talking about what happens when real-time action is stopped instantly so that some menu can appear, in doing so, disabling player input.
To elaborate on my question:
Is there a common way to accomplish this function?
Do you know of a particularly elegant and brief way to accomplish it?
In Unity the most common way to do this is:
// Pause
Time.timeScale = 0;
// Unpause
Time.timeScale = 1;
I think that’s about as brief and elegant as you could get too.
This works because Rigidbodies and most well written user scripts use Time.time and Time.deltaTime to do their processing. With time scale set to 0, no time will pass according to those functions.
2 Likes
Exactly what Praetor above said… and I would have a separate scene that is your “pause menu” that is additively loaded at level start.
The key is in the pause menu scene you have a Canvas and UI Image that covers the entire screen and has Raycast Target enabled to block UI touches.
You hide that hierarchy and the rest of your menu whenever Time.timeScale is above zero. When Time.timeScale becomes zero, you show the pause canvas and have a button that lets you set it back to 1.0f.
1 Like