TimeScaleManager - Implement Pause & Slow Motion in Unity
Wouldn't it be great if you could just stop time in between? In real life, we are unfortunately denied this ability. But in Unity you can manipulate time. You can slow it down or even pause it completely. And to make this possible from everywhere, I wrote the TimeScaleManager.
How to stop Time
The TimeScaleManager is again a relatively small, but very useful helper. The time can be paused and also stopped. In addition, you can check whether the time has just been stopped and react accordingly. Behaviours use this aspect, for example, to mute AudioSources when the player has paused the game.
You can pause the game:
TimeScaleManager.service?.Pause();
You can then resume the game:
TimeScaleManager.service?.Resume();
You can also set the time scale to a specific value:
TimeScaleManager.service?.SetTimeScale(0.5f);
And you can check if the game is paused:
if (TimeScaleManager.service?.IsPaused) {
// Do stuff...
}
Your Feedback is important!
What do you think of the services presented here? Is there anything missing or does something not work as expected? As always, I'm happy to listen to your feedback. Let me know what you think about this module. You can use the comment section below the article for this. You can also find other ways to contact me here. If you found a bug or want an enhancement, please create an issue in the GitHub repository. Further documentation can be found in the README of the corresponding module.
There are no comments yet.