Closing/hiding an open Gui Button when clicking on it

Hi everyone,

I have a GUI Button I would like to hide when I click on it. I’ve attempted to code it, but no luck so far. Here’s what I have so far. Any help would be much appreciated.

var buttonWidth:int = 200;
var buttonHeight:int = 50;
var spacing:int = 100;
var windowOpen = true;

function OnGUI() {

	if (windowOpen)
	{
	GUI.Button(Rect(Screen.width/2 - buttonWidth/2, Screen.height/2 - buttonHeight/2 - spacing, buttonWidth, buttonHeight), "Click to Close");
	{
	windowOpen = false;
	}
	}
}

You need to put an if in front of the button as well, something like this:

`
if( GUI.Button(Rect(Screen.width/2 - buttonWidth/2, Screen.height/2 - buttonHeight/2 - spacing, buttonWidth, buttonHeight), "Click to Close"))
    {
    windowOpen = false;
    }

`

Don’t forget to take out the semicolon at the end of the if statement once you do that!