I am trying to build a quiz game. I got two scripts, a Question Data and a Question Manager script. In my QuestionManager script i keep getting this error when i try to set a new question. I've tried to resolve it but i can't seem to get it fixed.
Error
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[Question].get_Item (Int32 index) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/EqualityComparer.cs:84)
**QuestionManager.SetNewQuestion () (at Assets/QuestionManager.cs:30)
QuestionManager.Start () (at Assets/QuestionManager.cs:21)**
this is my QuestionManager script
public class xxxxxxx {
[SerializeField]
private TextAsset questionDataXMLFile;
public QuestionData questionData;
private Question currentQuestion;
[SerializeField]
private Text factText;
void Start() {
questionData = QuestionData.LoadFromText(questionDataXMLFile.text);
factText = GetComponent ();
SetNewQuestion ();
}
public void SetNewQuestion()
{
int index = Random.Range(0, questionData.questions.Count - 1);
Debug.Log (index);
currentQuestion = questionData.questions[index];
factText.text = currentQuestion.questionText
}
// Use this to see if user selected correct answer
public bool CorrectAnswerSelected(int selectedAnswerID) {
return selectedAnswerID == currentQuestion.correctAnswerID;
}
}
↧