I have an array with X number of items in it (text).
What I’d like to do is create a GUI window to display each item, one at a time, with a “next” button that would advance to the next window in the sequence.
The user would step through each item, until reaching the last one in the array.
Ideally the window would actually disappear, and a new one would pop up with each following item.
Well, after messing around a bit I can mostly answer my own question.
Quite simple after all:
var questionsArray : String[]; //array of items entered via Inspector
var thisQ : int = 0; //which array item to begin at
function OnGUI () {
windowRect = Rect(10,10,200,100);
windowRect = GUI.Window (0, windowRect, DoQWindow, "Questions"); // Registers the window
}
// creates a window with 1 array item, on a button
// clicking the "next" button advances to the next item
// stops when it's gone through the whole array
function DoQWindow(window : int){
if (thisQ < questionsArray.Length){
GUILayout.Button(questionsArray[thisQ]);
GUILayout.Space(25);
if (GUILayout.Button("Next")){
thisQ++;
}
}
else{
print("no more questions!");
}
}
And of course now I can add a more detailed array, that would display a few buttons and a label at the same time.
As well as what happens when you click them. So I’m pretty happy.
The only thing I couldn’t figure out is how to make the window disappear/reappear between each loop.