public void AddQuestion() { string[] answersToAdd = new string[4] { answerField0.text, answerField1.text, answerField2.text, answerField3.text }; answersToAdd = OrderIn.Shuffle <string>(answersToAdd); int i = 0; foreach (string answer in answersToAdd) { if (answer == answerField0.text) { break; } else { i++; } } qM.AddQuestion(questionField.text, answersToAdd, i); }
public void ShuffleAll() { //Copy the list to shuffle List <Question> copy = GetCurrentTest().questions.ToList(); // List <Question> list = GetCurrentTest().questions; // //for every item in the list, replace it with a random item in the copied list and then remove it for (int item = 0; item < list.Count; item++) { int randomItem = (int)Random.Range(0, copy.Count); list[item] = copy[randomItem]; string rightAnswer = list[item].answers[list[item].rightAnswer]; list[item].answers = OrderIn.Shuffle(list[item].answers); int i = 0; foreach (string answer in list[item].answers) { if (answer == rightAnswer) { list[item].rightAnswer = i; break; } else { i++; } } copy.RemoveAt(randomItem); } Debug.Log(list.Count); }