Pause game without using timeScale

Hi all,

As the title suggests, is there are simple way to pause a game without using Time.timeScale? I haven’t decided on how I want the pause functionality will work in my game, but I can see problems I may run into if I use the “timeScale” method.

What are other ways to pausing a game?

Pls try to give examples in C#.

Thank you in advance for your help.

With Unity 4.5, it is possible to use Time.timeScale, because there is also Time.unscaledDeltaTime and Time.unscaledTime for objects that don’t need to get paused. This is probably the easiest solution, since you don’t need to test for extra conditions like with the other solutions.

The other solutions would be to have a static ‘paused’ boolean somewhere (like make a static class Game, so it would be Game.paused), and either wrap all neccessary Update function code in an ‘if (!Game.paused)’, or add a behaviour to objects that disables other behaviours when Game.paused is true, and enables them when Game.paused is false.

You can use events for that. You can create an event manager that will call the function Pause() then you click a button. In your scripts you can create a function OnPause() and suscribe it to the event manager. Inside the OnPause() function you can handle the pausing logic for each script.

This is a great tutorial for events! Hope it helps.

Unity - Events

NOTE:: My way of solving this should only work for simpler 2D games that don’t heavily rely on the physics engine! Use at your own risk, ymmv.

I usually solve this with a global variable(or a singleton) for whether the game is paused or not, and then in any object the uses its update function to “act”, I check if the game is paused before I let it do anything.

Here’s some Code.

You need to make a script to hold all your global variables, (mine is GlobalVariables.js) and attach it to some object that will always be in your scene (like an empty object JUST for this).

#pragma strict

static var isPaused : boolean;

function Start () {
	isPaused = false;

Attach this to the empty object in your scene.

Now, inside of ANY object that has to “act”, change its update function to look like this.

function Update () {
    if(!GlobalVariables.isPaused ){
        //All your old code/update code goes in here!

And voila, your game doesn’t do anything when you set GlobalVariables.isPaused to true, but anything inside of OnMouseDown functions will still fire!

EDIT:: fixing words