My issue is probably a very noob issue. However I can’t seem to figure it out and it is driving my up the wall.
I am creating a quiz within a portion of my game. The questions come from a text file which I then put into an array.
//text file
//This is filler the syntax is:
//question, answer 1, answer 2, answer 3, answer 4, correct answer
//answer should come up correct for all of these
1 x 1, 1, 2, 11, 10,1,
1 x 1, 1, 2, 11, 10,1,
1 x 2, 1, 2, 12, 21,1,
1 x 3, 1, 2, 11, 10,1,
1 x 4, 1, 2, 11, 10,1,
1 x 5, 1, 2, 11, 10,1,
1 x 6, 1, 2, 11, 10,1,
1 x 7, 1, 2, 11, 10,1,
1 x 8, 1, 2, 11, 10,1,
1 x 9, 1, 2, 11, 10,1,
1 x 10, 1, 2, 11, 10,1,
in my script I do this:
var answer;
var answ;
var quiz = Resources.Load("multiplesof1") as TextAsset;
var quizData = quiz.text.Split(","[0]);
var quizArray = new array(quizData);
if (newQuestion == true){
numb = Random.Range(1, 10) * 6;
answer = quizArray[numb + 5][0];
newQuestion = false;
}
//my button for question 1 is this:
if(GUI.Button(Rect(.74 * Screen.width, .65 * Screen.height, .1 * Screen.width, .07 * Screen.height), quizArray[numb + 1])){
answ = 1;
if (answ == answer){
correct = true;
}
else {Debug.Log("Broken");}
}
// I set up a debug log of
Debug.Log (answer);
Debug.Log(answ);
Debug.Log (quizArray[numb+5][0])
all three debug logs return 1. However it always tells me its broken.
I know I must be doing something stupid. If you can spare a few seconds to tell me what I’m doing stupid it would be very much appreciated.