Pause With an exit button?

how would i make it so that when i pressed lets say ‘P’ it pauses the game and a button pop up saying exit and obviously when you hit exit it exits the the menu and when you hit ‘P’ again the menu disappears if anybody could help me it would be a big massive help,
I have try this code below but all it does is exit the game an start

function Update ()
{

       if(Input.GetKey("p"))

 GUI.Button(Rect(20,20,100,30),"Exit")

 	Application.LoadLevel("Main Menu");

}

im doing a school project and i need it done soon :frowning:
and if you like i would put you in the credits ?

Alright when you press “P” you should have the button appear, not the Application.LoadLevel stuff because that loads the level when you press “P”. When you press “P” you should set the timescale to 0 and instantiate a button. On the button you should have a script with a OnMouseDown function and have that have the Application load stuff. If you have any questions just ask I’ll be happy to help.

private var paused = false;

function Update(){
    if(Input.GetKeyDown("p")){
        if(paused){
            paused = false;
            Time.timeScale = 1;
        }else{
            paused = true;
            Time.timeScale = 0;
        }
    }
}

function OnGUI(){
if(paused){
    if(GUI.Button(Rect(Screen.width/2-75,Screen.height/2-15,150,30),"Exit to menu")){
        Application.LoadLevel("Main Menu");
        }
    }
}

This script draws a button when the game is paused(press “p”) and if you click it, it will load the Main Menu.

A basic example. I am not keen doing your homework, but I hope you’ll learn something from this.

Code is not tested and is meant as an example.