- Home /
How to turn a label off as the next button is pressed in a Quiz game
pls help!i'm trying to create a quiz game and i have modified a script to have a background window and a question would come up each time the user presses next question but my challenge now is the previous questions (in form of labels)refuse to disappear as the next question comes up i.e they are all one the same window which i dont want. i want the previous questions to disappear as the user presses the "next button". Pls any hlp wud b greatly appreciated. you can modify and even suggest new codes that i can use. tanx in advance. This is my code
#pragma strict
var gameMessageFont : Font;
var isBoxShowing : boolean = false;
var isBox2Showing : boolean = false;
var isBox3Showing : boolean = false;
function OnGUI() {
GUI.skin.font = gameMessageFont;
GUI.Box(Rect(0, 0, 850, 290), "Exam");
if (!isBoxShowing && GUI.Button(Rect(360, 250, 150, 30), "Next Question")) {
isBox2Showing = true;
}
if(isBox2Showing) {
GUI.Label(Rect(0, 0, 850, 290), "Question 2");
if (!isBoxShowing && isBox2Showing && GUI.Button(Rect(160, 250, 150, 30), "To Question 3")) {
isBox3Showing = true; } } if(isBox3Showing) { GUI.Label(Rect(100, 0, 850, 290), "Question 3"); if (!isBoxShowing && isBox2Showing && isBox3Showing && GUI.Button(Rect(560, 250, 150, 30), "To Question 4")) { } } }
If the labels are all in the same place could store the question in a variable and just change that?
Answer by dscroggi · Jan 22, 2014 at 12:45 AM
Something like this maybe?
var gameMessageFont : Font;
var current : int = 0;
var questions : String[];
function Start ()
{
GUI.skin.font = gameMessageFont;
questions = ["Question 1", "Question 2"];
}
function OnGUI ()
{
GUI.Label(Rect(0, 0, 850, 290), questions[current]);
if(GUI.Button(Rect(160, 250, 150, 30), "To Question " + current.ToString()))
{
current = current++ % questions.Length;
}
}
tanx for d reply i appreciate it, but ur code is not doin anytin when the "to question 1" button is pressed. i want a quiz kinda game whr different questions in different windows can be seen. for example, question 1 is in one window and when i press the "next question" button another window with question 2 pops up while the previous question (question 1) disappears.and if i press the "next question" button, question 3 pops up in another window while question 2 disappears and so on till question 10. pls help me out here.... tanx in advance.
Your answer
Follow this Question
Related Questions
Changing Button/Label text size? 2 Answers
Displaying Level 1 Answer
Where are asset labels stored? 1 Answer
GUI.Label appers bad when font size is too big 3 Answers
how to make global labels in front and GUI.BringWindowToBack(ID); 1 Answer