how do you exit GUI

hi im trying to make a logout screen ive made it so when you click on a little x it opens a label with some text and buttons, my yes button takes me back to the main menu i want to know how to make it exit my main label and all the buttons and text here is the code:

public bool exitbuttonclicked = false;

public float exitLabelTextLeft = 300;
public float exitLabelTextRight = 7;
public float exitLabelTextWidth =  100;
public float exitLabelTextHeight = 100;

public float noExitButtonLeft = 738;
public float noExitButtonRight = 50;
public float noExitButtonWidth = 20;
public float noExitButtonHeight = 20;   

public float yesExitButtonLeft = 738;
public float yesExitButtonRight = 50;
public float yesExitButtonWidth = 20;
public float yesExitButtonHeight = 20;

public float closeButtonPosLeft = 50;
public float closeButtonPosRight = 50;
public float closeButtonHeight = 20f;
public float closeButtonWidth = 20f;

public float exitBarLabelLeft = 738;
public float exitBarLabelRight = 20;
public float exitBarLabelHeight = 200;
public float exitBarLabelWidth = 200;

    //changes exitbutton clicked to be true
    if(GUI.Button(new Rect(closeButtonPosLeft, closeButtonPosRight, closeButtonWidth, closeButtonHeight),"x", closeButtonStyle)) {
        exitbuttonclicked = true;
    }

    //displays exitbuttonlogout screen
    if (exitbuttonclicked)
    {
        //displays logout box
        GUI.Label(new Rect(exitBarLabelLeft, exitBarLabelRight, exitBarLabelWidth, exitBarLabelHeight), logoutImage);

        //displays the text 
        GUI.Label(new Rect(exitLabelTextLeft, exitLabelTextRight, exitLabelTextWidth, exitLabelTextHeight), "Are you sure you wish to exit?");

        //the yes button
        if(GUI.Button(new Rect(yesExitButtonLeft, yesExitButtonRight, yesExitButtonWidth,yesExitButtonHeight), "Yes")) {
            Application.LoadLevel("Main Menu");
        }
        // the no button
        if(GUI.Button(new Rect(noExitButtonLeft, noExitButtonRight, noExitButtonWidth, noExitButtonHeight), "No")) {
            Debug.Log("No Clicked");

        }
    }

i would prefer c# please i'm not very good at JavaScript

thanks in advance

Are you saying you want the "No" button to hide the logout confirmation that the "x" button opens? If so then just setting exitbuttonclicked back to false should be all you need.

It's not quite clear, but I'll try and cover all bases in case one of them is what you are looking for.

If you want the No button to just hide the dialogue - it's pretty simple... Just change exitbuttonclicked back to false:

// the no button
if(GUI.Button(new Rect(noExitButtonLeft, noExitButtonRight, noExitButtonWidth, noExitButtonHeight), "No")) {
    Debug.Log("No Clicked");
    exitbuttonclicked = false;
}

When you load a new scene, this script should be destroyed, so you shouldn't have problems with leftover labels or buttons or anything. Is that what you want? If it's not destroyed (if you used Object.DontDestroyOnLoad), you can destroy it manually using Object.Destroy.

    //the yes button
    if(GUI.Button(new Rect(yesExitButtonLeft, yesExitButtonRight, yesExitButtonWidth,yesExitButtonHeight), "Yes")) {
        // This next line will actually destroy this script, unless it was marked as DontDestroy()
        Application.LoadLevel("Main Menu");
    }

If you want to keep the script alive, but don't display anything, you can do something like

public bool bDisplayGUI = true;

public void OnGUI()
{
    if (!bDisplayGUI)
        return;

    // Rest of your code goes after this
    ...
}

Just take into acount that OnGUI() will run potentially several times each frame, and do nothing, but will waste resources while doing it (since obviously it still needs to be called by Unity).

The next option would be to just disable the script...

//the yes button
if(GUI.Button(new Rect(yesExitButtonLeft, yesExitButtonRight, yesExitButtonWidth,yesExitButtonHeight), "Yes")) 
{
    // This next line will actually destroy this script, unless it was marked as DontDestroy()
    Application.LoadLevel("Main Menu");
    this.enabled = false;
}

I hope that's what you were after...