I have a more complicated script that I’ve been working on. It’s designed to organize the answers(dic[x,2-5]) randomly to all the questions available. It also keeps track of the correct answer(dicnum) and the secondary answer(splitnum) which is used to make a 50/50 function.
However, for some odd reason either a loop is created or some other unknown error appears and causes Unity to crash.
{for (int currentQuestion = 0; currentQuestion < 10; currentQuestion++) {
a = 0;
b = 0;
c = 0;
for (int j = 2; j<6; j++) {
t = (int)UnityEngine.Random.Range (2, 6);
if (t == j || t == a || t == b || t == c)
while (t == j || t == a || t == b || t == c)
{t = (int)UnityEngine.Random.Range (2, 6);}
variable = QuestionData.dic [currentQuestion, j];
QuestionData.dic [currentQuestion, j] = QuestionData.dic [currentQuestion, t];
QuestionData.dic [currentQuestion, t] = variable;
if (QuestionData.dicnum [currentQuestion] == (j - 1))
QuestionData.dicnum [currentQuestion] = t - 1;
if (QuestionData.splitnum [currentQuestion] == (j - 1))
QuestionData.splitnum [currentQuestion] = t - 1;
if (QuestionData.dicnum [currentQuestion] == (t - 1))
QuestionData.dicnum [currentQuestion] = j - 1;
if (QuestionData.splitnum [currentQuestion] == (t - 1))
QuestionData.splitnum [currentQuestion] = j - 1;
c = b;
b = a;
a = t;
}}}
I’ve tried commenting out the if statements toward the end, which are used in order to transfer the values for the correct and secondary answers. Unity becomes functional when I comment this out, but it doesnt keep track of the correct answer anymore. Commenting out the while, which is used to ensure that no random number is selected twice, has similar results.
Anyone have any idea what is causing the crash? Any advice on how to fix it?