I need to make structural GUI like something in the following scheme:
Button 1 Button 2
|| /\ || /\
\/ || | \/ ||
Button 1.1 Button 1.2 Back | Button 2.1 Button 2.2 Back
Each level is displayed alone - they are not stacked in height, they change lines by clicking buttons (e.g. Only Button 1 and 2 are displayed - clicking Button 1 will show only Buttons 1.1 and 1.2 and Back).
I thought of making a coroutine that will be something like:
IEnumerator GetGUIInput()
{
while(true)
{
if(GUI.Button(new Rect(0, 0, 100, 100), "Button 1"))
{
while(!GUI.Button(new Rect(200, 0, 100, 100), "Back"))
{
if(GUI.Button(new Rect(0, 0, 100, 100), "Button 1.1"))
{
// Do something
break;
}
else if(GUI.Button(new Rect(100, 0, 100, 100), "Button 1.2"))
{
// Do something
break;
}
yield return 0;
}
}
else if(GUI.Button(new Rect(100, 0, 100, 100), "Button 2"))
{
while(!GUI.Button(new Rect(200, 0, 100, 100), "Back"))
{
if(GUI.Button(new Rect(0, 0, 100, 100), "Button 2.1"))
{
// Do something
break;
}
else if(GUI.Button(new Rect(100, 0, 100, 100), "Button 2.2"))
{
// Do something
break;
}
yield return 0;
}
}
yield return 0;
}
}
But it won't work.... because GUI.Button works only within OnGUI.
So I mixed up this:
IEnumerator GUIInputState;
void Start()
{
GUIInputState = GetGUIInput();
}
void OnGUI()
{
GUIInputState.MoveNext();
}
Which works fine.... but it seems like rewriting StartCoroutine, and it will turn into a complete mess when I will need things like
yield return new WaitForSeconds(1);
Is there a way of making a coroutine be called only within OnGUI or I have to rewrite StartCoroutine?
Are you sure you need a coroutine? I would think standard OnGUI scripting would accomplish this.
– DaveAIt cannot - after pressing Button 1 I will need to start using states to know what state it is in and it will get messy.
– anon54314536Messy is not the same as "cannot". :-)
– Bampf