So I am making a questionnaire. There is 1 question and 4 possible answers. Only one answer is correct however. I will have over 1000 questions and over 4000 answers. If the user chooses the correct answer I don’t want that question to be asked again… If he chooses the wrong answer, then move to the next question randomly but leaving the last question in the pile to be asked again later on. So this is how I am going about it so far. But before I go any further I feel there is a MUCH better way of doing this and will save me some time/efficiency. Any advice is appreciated…
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class QAndA : MonoBehaviour {
public List<string> Questions;
public List<string> Answers;
public List<string> IncorrectAnswers;
int question = 0;
public bool correct;
void Awake()
{
//-------------Questions-----------------//
Questions[0] = "What is 2+2?";
Questions[1] = "What is 5+5?";
//-------------Answers-------------------//
Answers[0] = "4";
Answers[1] = "10";
//-------------Incorrect Answers---------//
IncorrectAnswers[0] = "22";
IncorrectAnswers[1] = "2";
IncorrectAnswers[2] = "44";
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
switch (question)
{
case 0:
GUI.Label(new Rect(25, 25, 125, 50), Questions[0]);
if(GUI.Button(new Rect(125,25,125,50), Answers[0]))
{
//Move to the next question, but allow this question to be asked again
//At a randomly later time.
if (correct) { question = Random.Range(0, Questions.Count); }
}
if (GUI.Button(new Rect(125, 75, 125, 50), IncorrectAnswers[0]))
{
//Move to next question randomly and keep this question from being
//asked again.
Questions.Remove(Questions[0]);
question = Random.Range(0, Questions.Count);
}
break;
case 1:
GUI.Label(new Rect(25, 25, 125, 50), Questions[1]);
if (GUI.Button(new Rect(125, 25, 125, 50), Answers[1]))
{
//Move to next question randomly
if (correct) { question = Random.Range(0, Questions.Count); }
}
break;
case 2:
GUI.Label(new Rect(25, 25, 125, 50), Questions[2]);
if (GUI.Button(new Rect(125, 25, 125, 50), Answers[2]))
{
//Move to next question randomly
if (correct) { question = Random.Range(0, Questions.Count); }
}
break;
case 3:
GUI.Label(new Rect(25, 25, 125, 50), Questions[3]);
if (GUI.Button(new Rect(125, 25, 125, 50), Answers[3]))
{
//Move to next question randomly
if (correct) { question = Random.Range(0, Questions.Count); }
}
break;
case 4:
GUI.Label(new Rect(25, 25, 125, 50), Questions[4]);
if (GUI.Button(new Rect(125, 25, 125, 50), Answers[4]))
{
//Move to next question randomly
if (correct) { question = Random.Range(0, Questions.Count); }
}
break;
}
}
}