Click on the button and then hide the button, how ?

I am trying to manage it like this -

	if (Input.GetKey(KeyCode.Escape))
    {
			Time.timeScale = 0.0f; // paused the game
			
			if (GUI.Button(new Rect(230, 440, 500, 50), "QUIT")){
       Application.Quit();}
				else if (GUI.Button(new Rect(230, 495, 500, 50), "NO")){
					Debug.Log("dont quit, hide these 2 buttons and continue playing");
			Time.timeScale = 1.0f; // resumed the game
			}
    }

what should i write in else if, so that it returns to game scene and hide these buttons?

This will never run because it is only going to be updated when you press escape. You need to have a state that changes in your OnGUI call to display different GUI buttons.

private int guiIndex = 0;

    void OnGUI()
    {
        switch (guiIndex)
        {
            case 0:
                GUI.Label(testRect, "This is case 0 gui text");
                break;

            case 1:
                GUI.Label(testRect, "This is case 1 gui text");
                break;
        }
    }

You can then use escape to switch your guiIndex number to something else.

I’m not even sure if that pausing system works (I have yet to actually work on one, so no experience there although I have ideas) but you can also do this with a boolean value.

So:

  • In update, check if the Escape key is pressed. If so, change OnMenu to true (or whatever name you wish)
  • In the OnGUI, the entire thing for the menu will be covered in an if(OnMenu)
  • Make the second button to close the menu change OnMenu to false

You can also make the Escape key as well to open AND close the menu if you wish. Just make it like this: (sorry for the quick, ugly code)

if(Get.Key(Escape)){
if(!OnMenu) OnMenu = true;
else OnMenu = false;
}

Edit @Dantus: (Trying not to make an additional post) Sorry about that. I didn’t notice, and I guess trying to rush with an iffy internet connection wasn’t the best idea.

Thanks for the double post!

This code is not working, it freezes my app, what’s wrong ??
Anyone knows how can i achieve this ??

if (Input.GetKey(KeyCode.Escape))
		{
			showExitMenu = true;
			Time.timeScale = 0.0f;
		}
		
		if (showExitMenu)
		{
			if (GUI.Button(new Rect(230, 440, 500, 50), "Quit"))
			{
				exitApp = true;
			}
			
			if (GUI.Button(new Rect(230, 495, 500, 50), "NO"))
			{
				showExitMenu = false;
				Time.timeScale = 1.0f;
			}
		}
		
		if (exitApp)
		{
			
			Application.Quit();
		}
		else 
		{
			return;
		}

Wanna make it like this -

using UnityEngine;
using System.Collections;

public class Dialog : MonoBehaviour {
	public bool showDialog = false;
	public void Update () {
		if (Input.GetKeyDown(KeyCode.Escape)  !showDialog) {
			showDialog = true;
			Time.timeScale = 0f;
		}
	}
	public void OnGUI () {
		if (showDialog) {
			if (GUI.Button(new Rect(10, 10, 300, 200), "Quit")) {
				#if UNITY_WEBPLAYER
				Application.ExternalEval("document.location = 'http://unity3d.com/';");
				#else
				Application.Quit();
				#endif
			}
			if (GUI.Button(new Rect(Screen.width - 310, 10, 300, 200), "No")) {
				showDialog = false;
				Time.timeScale = 1f;
			}
		} else {
			GUI.Label(new Rect((Screen.width - 100) / 2, Screen.height / 2, 200, 30) ,"Press Esc To Show Dialog");
		}
	}
}

http://dl.dropboxusercontent.com/u/16199081/Dialog/Test.html