Gui Question (sorry the gui forum isn't very active and it's time sensitive)

Hello all,

I’m trying to get more gui elements to show up when I click a button in a menu for nested menus. I had assumed the following code would work:

void OnGUI(){
		if(GUI.Button(new Rect(0,0,100,100),"Test Button")){
					GUI.Box(new Rect(150,150,40,100), "The Button is Clicked");
		}
	}

but it does not work as expected. The Gui box never shows up. If I move the Gui box code outside the conditional, it shows up as expected. I’m curious how I’d get functionality like this to work.

Thanks much

The problem is the GUI.Button conditional is only true for a split second, so that’s the amount of time it will show your GUI.Box for. What you could do is have a boolean value that determines if the GUI.Box should be drawn.

bool showBox = false;

void OnGUI(){
    if(GUI.Button(new Rect(0,0,100,100),"Test Button")){
        showBox = true;
    }
    if (showBox)
        GUI.Box(new Rect(150,150,40,100), "The Button is Clicked");

}

I see :frowning:

If I used a toolbar, will that always return a value? I’m trying to make a menu system, so I planned on using a toolbar anyway but was just testing with a button. If I switched to that and used a switch statement would that work do you think?

I’ve only used a toolbar once, but I think that’s the way to do it. Just put your GUI.Box in the switch statement and it should work just fine. And yes, the toolbar always returns a value (99.9% sure).