Deleting a Gui Box

Hello everyone, i have a very simple question. How can i delete a gui box after pressing any of the buttons on it ?

here is my code :

static var guivar= 0;
var f : Font;
var f2 : Font;

function OnGUI () {
if(guivar==1)
{ 

	GUI.skin.font = f;
	GUI.Box (Rect (150,230,380,100), "FlightTime");
	
	
	GUI.skin.font = f2;
	
	if (GUI.Button (Rect (160,270,100,30), "5 Min")) 
	{
	Timer.seconds = 59;
	Timer.minutes= 04;

		
	}
	
	
	if (GUI.Button (Rect (285,270,100,30), "10 Min")) {
		Timer.seconds= 59;
	Timer.minutes = 09;
	
	}
	
	if (GUI.Button (Rect (417,270,100,30), "15 Min")) {
		Timer.seconds = 59;
	Timer.minutes = 14;
	
	 
	}
	

}

}

please helpm me :slight_smile:

You can’t ‘delete’ a gui box as it doesn’t exist as a real object in Unity’s immediate mode GUI. It only exists when your code actually draws it. As you have the above code wrapped in a boolean, simply change the state of guivar whenever you click the button.

GUI is rendered at realtime.

if(drawBox)
{
//draw the box and all it’s GUI object
if(GUI.Button(“Nuke box from orbit”))
{
drawBox = false
}
}

Now, when drawBox is false, every GUI object within the clause will not be rendered.