- Home /
GUI.Toolbar with deselect option
Is there a simple way to create the GUI.Toolbar with deselect option, so that clicking a selected button would deselect it and set the .selected index to -1 or similar?
Answer by Kourosh · Apr 29, 2011 at 01:51 PM
Try this one:
var toolbarInt : int = -1; var lastbarInt : int; var toolbarStrings : String[] = ["Toolbar1", "Toolbar2", "Toolbar3"];
function OnGUI () { toolbarInt = GUI.Toolbar (Rect (25, 25, 250, 30), toolbarInt, toolbarStrings); if(GUI.changed){ if(lastbarInt == toolbarInt){ toolbarInt = -1; } lastbarInt = toolbarInt; } }
Thanks. Almost the same as I've created myself, but $$anonymous$$e was missing the condition (GUI.changed) and that is probably why it was not working as expected.
Answer by Siegeon · Apr 29, 2011 at 01:53 PM
Sure, you could have a button that sets a bool such as Toolbar active. Then in your on GUI method check the bool before drawing the tool bar
Code untested.
public class GUIManager : MonoBehaviour{
private bool toolbarActive;
void OnGUI()
{
//show the topmost menu if we have one
if (toolbarActive())
{
//Draw your toolbar here
}
//this would be the button control separate from your toolbar
if (GUI.Button(new Rect(10, 10, 50, 50), btnTexture))
toolbarActive = !toolbarActive;
}
}
Answer by Uzquiano · Apr 29, 2011 at 01:39 PM
You must code it by yourself, or try to search in the wiki