Hi,
So I have a script and I’m getting the error Argument Out Of Range Parameter Name: Index, but I don’t know why. I’ve done some looking around, and I’ve seen people saying their list or something has nothing in it, which would make sense, but to my knowledge, I don’t. So I know this is kind of a silly question, but if anyone could help me it would be much appreciated. Here’s my code:
public void MultChoice(){
if (multChoice.Count > 0) {
multChioce1.GetComponentInChildren<Image> ().color = Color.white;
multChioce2.GetComponentInChildren<Image> ().color = Color.white;
multChioce3.GetComponentInChildren<Image> ().color = Color.white;
multChioce4.GetComponentInChildren<Image> ().color = Color.white;
correctButtonNumber = (int)UnityEngine.Random.Range (0, 3);
tempIntMult = UnityEngine.Random.Range (0, multChoice.Count);
randomizedTextMult.text = hir2 [tempIntMult];
int one = UnityEngine.Random.Range (0, rom2.Count);
rom2.RemoveAt (one);
int two = UnityEngine.Random.Range (0, rom2.Count);
rom2.RemoveAt (two);
int three = UnityEngine.Random.Range (0, rom2.Count);
rom2.RemoveAt (three);
int four = UnityEngine.Random.Range (0, rom2.Count);
rom2.RemoveAt (four);
switch (correctButtonNumber) {
case 0:
multChioce1.GetComponentInChildren<Text> ().text = rom2 [tempIntMult];
multChioce2.GetComponentInChildren<Text> ().text = rom2 [two];
multChioce3.GetComponentInChildren<Text> ().text = rom2 [three];
multChioce4.GetComponentInChildren<Text> ().text = rom2 [four];
rom2.Add (multChioce1.GetComponentInChildren<Text> ().text);
rom2.Add (multChioce2.GetComponentInChildren<Text> ().text);
rom2.Add (multChioce3.GetComponentInChildren<Text> ().text);
rom2.Add (multChioce4.GetComponentInChildren<Text> ().text);
break;
case 1:
multChioce1.GetComponentInChildren<Text> ().text = rom2 [one];
// I think the error is on the line above.
multChioce2.GetComponentInChildren<Text> ().text = rom2 [tempIntMult];
multChioce3.GetComponentInChildren<Text> ().text = rom2 [three];
multChioce4.GetComponentInChildren<Text> ().text = rom2 [four];
rom2.Add (multChioce1.GetComponentInChildren<Text> ().text);
rom2.Add (multChioce2.GetComponentInChildren<Text> ().text);
rom2.Add (multChioce3.GetComponentInChildren<Text> ().text);
rom2.Add (multChioce4.GetComponentInChildren<Text> ().text);
break;
case 2:
multChioce1.GetComponentInChildren<Text> ().text = rom2 [one];
multChioce2.GetComponentInChildren<Text> ().text = rom2 [two];
multChioce3.GetComponentInChildren<Text> ().text = rom2 [tempIntMult];
multChioce4.GetComponentInChildren<Text> ().text = rom2 [four];
rom2.Add (multChioce1.GetComponentInChildren<Text> ().text);
rom2.Add (multChioce2.GetComponentInChildren<Text> ().text);
rom2.Add (multChioce3.GetComponentInChildren<Text> ().text);
rom2.Add (multChioce4.GetComponentInChildren<Text> ().text);
break;
case 3:
multChioce2.GetComponentInChildren<Text> ().text = rom2 [one];
multChioce2.GetComponentInChildren<Text> ().text = rom2 [two];
multChioce2.GetComponentInChildren<Text> ().text = rom2 [three];
multChioce4.GetComponentInChildren<Text> ().text = rom2 [tempIntMult];
rom2.Add (multChioce1.GetComponentInChildren<Text> ().text);
rom2.Add (multChioce2.GetComponentInChildren<Text> ().text);
rom2.Add (multChioce3.GetComponentInChildren<Text> ().text);
rom2.Add (multChioce4.GetComponentInChildren<Text> ().text);
break;
}
} else {
randomizedTextMult.text = "Done";
multChioce1.GetComponentInChildren<Text> ().text = "";
multChioce2.GetComponentInChildren<Text> ().text = "";
multChioce3.GetComponentInChildren<Text> ().text = "";
multChioce4.GetComponentInChildren<Text> ().text = "";
}
}
and in a separate script,
public void CheckAnswerMultipleChoiceButtonOne ()
{
int hirTemp = hManager.hir2.IndexOf (hManager.randomizedTextMult.text);
int romTemp = hManager.rom2.IndexOf (hManager.multChioce1.gameObject.GetComponentInChildren<Text> ().text);
if (hirTemp == romTemp) {
hManager.randomizedArray.RemoveAt (hManager.tempIntMult);
hManager.MultChoice ();
//Or here?
hManager.attempts = 0;
} else {
hManager.attempts++;
if (hManager.attempts == 3) {
switch (hManager.correctButtonNumber) {
case 0:
hManager.multChioce1.GetComponentInChildren<Image> ().color = Color.green;
if (hirTemp == romTemp) {
hManager.randomizedArray.RemoveAt (hManager.tempIntMult);
hManager.MultChoice ();
hManager.attempts = 0;
}
break;
case 1:
hManager.multChioce2.GetComponentInChildren<Image> ().color = Color.green;
if (hirTemp == romTemp) {
hManager.randomizedArray.RemoveAt (hManager.tempIntMult);
hManager.MultChoice ();
hManager.attempts = 0;
}
break;
case 2:
hManager.multChioce3.GetComponentInChildren<Image> ().color = Color.green;
if (hirTemp == romTemp) {
hManager.randomizedArray.RemoveAt (hManager.tempIntMult);
hManager.MultChoice ();
hManager.attempts = 0;
}
break;
case 3:
hManager.multChioce4.GetComponentInChildren<Image> ().color = Color.green;
if (hirTemp == romTemp) {
hManager.randomizedArray.RemoveAt (hManager.tempIntMult);
hManager.MultChoice ();
hManager.attempts = 0;
}
break;
}
}
}
}
Thanks!