How to pause a game?

Here’s the problem: I’d like to pause the game but still have my menus work. If I set time.scale = 0.0, it pauses everything in the game, including my animated menus (which are game objects).

Ideally what I’d like to do is set the time scale for groups of objects or layers in the scene, but as far as I know that’s not possible.

The only other choice I can think of is to do it by brute force through scripting, which is an ugly prospect. My game has a lot of complex behaviors that trigger each other with timed delays. I’d have to intercept all of those delays and rebuild them from the point they were paused, which opens the door to a lot of potential bugs.

Is there some other approach I’m overlooking?

assuming they don’t use physics, you can make your gui objects immune by just calculating the real time elapsed using Time.realtimeSinceStartup; there’s no equivilant realtimeDelta, but you could calculate your own by storing the realtime of the previous update in a variable. Something like this…

private var prevTime:float=0;
function Update()
    var timeNow=Time.realtimeSinceStartup;
    var deltaRealtime=timeNow-prevTime;

    //then write your existing code, using deltaRealtime instead of 
    //Time.deltaTime or timeNow instead of Time.time for any lerps or other
    //time-based calculations


This could potentially cause issues if your framerate drops significantly, and realtime gets way out of synch with game time, but depending on what you’re doing with the gui objects it may not be a real problem.

The solution I’ve chosen is to pause the playback of key elements via script and to leave the time scale untouched. This involved creating a handler for time triggers that keeps track of every trigger. When the game is paused, all active triggers get stopped and their current times recorded. When the user resumes the game, all of the triggers are recreated from the time it was paused. Any behaviors/animations that started before the pause continue to play, but new ones won’t trigger. So in effect, the pause is a ‘living hold’, which in some ways is better than a 100% pause.

Thanks WillTAtl for your help.