Unity 2D: How to create a Pause Game Dialog

Hi all

I’m a new one in Unity, and I’m developing a simple pluzze game using Unity 2d.

I have a question: How do I make a Pause game dialog, it’s visible on Scene when user press Back button (on Mobile device). After that, user can select “Continues” to back to recent Scene, or select “Quit” to next Scene.

I’ve try to user GUI, but I don’t know how to call visible Dialog, and how to close dialog created by GUI.

Any body can help me ?
Thanks all :slight_smile:


I would do it like this (i’ll do it in JS):
let’s say i have a box that move - it can be any object.

  1. make a script that manages the pausing and put it where you think its most fit, let’s call the script ‘PauseScript’
  2. I would create a static boolean variable that is called ‘isPaused’ that is set to false since the game isnt starting paused.

static var isPaused:boolean = false;

In case the box moved with ‘transform.translate’:

  1. in the ‘Update Function’, before moving the object I would write the lines

the movement command //ie. transform.translate, transform.position.x= act…

since the pause variable is static, it has only 1 instance and it
can be accesed from anywhere by going to its containing script - thus: PauseScript.isPaused

if you deal with a rigidbody object that recieves rigidbody.velocity through rigidbody.addforce,

  1. I would create a variable that can save its current speed (if the speed changes and affected by time, like movement caused by AddForce). let’s call it

var tempVelocity :Vector3;

  1. I would create a function “Pause” that, If PauseScript.isPaused==true, saves the current velocity to tempVelocity, and then set the rigidbody.velocity to 0.
  2. and another one that, If PauseScript.isPaused==false, gives rigidbody.velocity = tempVelocity,

thus the object freezes in place and resumes with the same speed one game resumes.
same you can do with rotation act…

hope it helps