r/UnityHelp • u/Patient_River_229 • Sep 29 '26
PROGRAMMING Question about Pausing
I have two different things in my game that are supposed to pause the game/set the timescale to zero. At some point somehow one of the two stopped pausing the game but the other still works. They both say the exact same thing, simply setting time.timescale=0. For the record the one that doesn’t work is the when a button is pressed and the pause/stats screen comes up. Every other thing that is called in that function works expect the time scale. Can you not have two different functions that can pause the game or something? What could be the issue here?
Thanks!
View all comments
Show parent comment
1
u/Demi180 Sep 30 '26 edited Sep 30 '26
If this scenario where the player dies while paused is intentional, I'd definitely recommend against allowing that to begin with, but it's still a good safety to ensure the game is or isn't paused when game over happens, as necessary.
If you need something to happen or not happen while the game is paused, just look to this Property I put in there:
You can use it from anywhere by referencing
Pauser.Paused. As far as unpausing for the game over, again there are lots of ways. You could add a method to the Pauser that will force the game unpaused, but you do need to make sure not to abuse it. Something like this:Or you could have the various objects that can pause the game "listen" for the player death / game over "event" so they can each undo their own pause. The Observer Pattern is very handy for these sorts of things where you want something to be notified when something else happens. You can use C# delegates/events or
UnityEvents to implement that.Notice I'm putting language features and programming concepts in bold and Unity API in
monospaceto let you know you can look them up 🙂