# Unity3D : Pause Menu - Android

I am making a 2D game for Android. Almost completed the game but now I need a pause game option. I added a pause icon on the top right side of the screen. The icon is a GUI texture. What I did so far :

I made a script which will bring up some buttons (which is not working) and attached it to the GUITexture.This is the script :

#pragma strict

function OnMouseDown() {
Time.timeScale = 0;

if (GUI.Button(Rect(10,10,100,50),"Restart"));

}


Now the problem stands at the part where the buttons won't show up and the game freezes at the first frame. Please if you can help I would be really thankful.

Edit #1 : I just noticed that when I click "Pause" the game freezes and it takes me to the MainMenu. That's because I added the GUIButton which takes you to the main menu. I think the whole script structure is wrong. I also forgot to mention that I am new to scripting/unity.

Thank you.

The problem here is that you're trying to access the GUI functions from outside the OnGUI function. You'll want to set some sort of variable indicating that the game is paused in the input event handler, and then alter the game's behaviour in the OnGUI function, like this:

function OnMouseDown(){
this.paused = !this.paused;
}

function OnGUI(){
if(this.paused){
if (GUI.Button(Rect(10,10,100,50),"Restart")){
// do something
}
// Insert the rest of the pause menu logic
}
}

• Hey,thanks for your reply your way seems more logical but it also gives me an error : "Assets/Scripts/Pause.js(4,10): BCE0019: 'paused' is not a member of 'Pause'. " Have you got any idea what this means ? – Ssiro Jun 7 '14 at 8:33
• add private var paused = false; – sertsedat Nov 7 '14 at 11:53