Confused about pausing

Hi All,

I’ve been looking through the forum for methods for pausing a game. I’ve got the Time.timeScale set to zero - that’s fine.

However not all my functions are time dependent. For example a function called from Update checks if a button is pressed and activates a power up. This is a one shot function and will trigger regardless of time scale.

At the moment the only thing I can think to remedy this is to have something like…

function Update ()
{
   if (GameHandler.instance.paused) return;

   OtherMethods ();
}

… at the top of the Update function before any methods are called. This seems like a lot of effort and quite easy to forget to do.

Is there a more standard/global approach to this problem?

The FixedUpdate function will not be called if your timescale is set to zero, so you might be able to put some of the one-shot controls in there. For GUI, there isn’t any way to pause other than to use the method you described above.

The way I’ve handled this in the past is to derive all component classes that need to be ‘pausable’ from a common base class (e.g. ‘Pausable’), and then, when the game is paused or unpaused, find all such objects using FindObjectsOfType() and enable/disable them as appropriate. (Doing the same thing with all particle system components will cause them to pause/unpause correctly as well.)

Thanks guys, some useful tips there. I was hoping there was some magic pause function but I guess you get lots of flexibility this way.