I want to have an Instructions button on screen all the time that will allow users to click it and always see the instructions for that part of the game. The text instructions are loaded in Start() into a string ArrayList and its count is correct.
While they are reading the instructions, I want three other buttons to appear: Next, which will go to the next chunk of instructions (if not at the end); Previous; and Exit Instructions. When they click on Exit, these three buttons should go away.
Nesting buttons seems not to work in OnGUI. My code just hangs, to the point where I need to use Task Manager to stop Unity entirely. My Debug.Log shows I am in OnGUI but I do not get the “Inside if Instructions” button. The function:
function OnGUI() {
Debug.Log("Inside function OnGUI");
if (GUI.Button(Rect(300, 0, 150, 50), "Instructions")) {
// Load the instructions into an array for display
Debug.Log("Inside if Instructions button in OnGUI");
seenInstruction1 = false;
// Put the first instruction on screen and make it visible
textHolder.text = instructions[0];
nextOkay = true;
Debug.Log("Inside Instructions code about to enter the while nextOkay =" + nextOkay);
while (seenInstruction1 == false) {
if (GUI.Button(Rect(460, 0, 150, 50), "Exit Instructions")) {
seenInstruction1 = true;
instructionCtr = 0;
prevOkay = false;
nextOkay = true;
textHolder.text = "";
}
if (nextOkay == true) {
if (GUI.Button(Rect(710, 0, 100, 50), "Next")) {
instructionCtr++;
prevOkay = true;
textHolder.text = instructions[instructionCtr];
if (instructionCtr >= instructionMax) {
nextOkay = false;
}
}
}
if (prevOkay == true) {
if (GUI.Button(Rect(820, 0, 100, 50), "Previous")) {
instructionCtr--;
nextOkay = true;
textHolder.text = instructions[instructionCtr];
if (instructionCtr == 0) {
prevOkay = false;
}
}
}
} // End of while seenInstruction1 == false
If there is a Unity Javascript control that will display a couple of hundred words of text without it being editable by the user, then I can just have one screen of instructions, and do without the Next/Previous buttons. However, I will still need a “Done” or “Exit Instructions” button to clear the instructions and return to the game.
I have tried moving the Instructions button so I don’t think that’s the issue. The “Test Game” button does display.
Any advice?