// Start is called before the first frame update void Start() { mc = MultipleChoice.getMultipleChoice(); question.GetComponent <InputField>().text = ""; correctAnswer.GetComponent <InputField>().text = ""; for (int i = 0; i < wrongAnswers.Length; i++) { wrongAnswers[i].GetComponent <InputField>().text = ""; } }
public void build_questions() //---------------------------------------------------------- // Get the txt file and build question bank from txt content //---------------------------------------------------------- { mc = MultipleChoice.getMultipleChoice(); if (mc != null) { if (mc.getQuestions().Count == 0) { warning.GetComponent <Text>().text = "no question in database"; } if (mc.getQuestions().Count > no_questions) //pick question from pool { List <int> rndList = new List <int>(); System.Random rnd = new System.Random(); for (int i = 0; i < no_questions; i++) { int random = rnd.Next(mc.getQuestions().Count); if (!rndList.Contains(random)) { rndList.Add(random); continue; } // if the number is duplicated then do this loop again. i--; } for (int i = 0; i < rndList.Count; i++) { Question quesObj = mc.getQuestions()[rndList[i]]; //temp string array, delimited by ;, first entry is the question, last entry is the correct answer string question = quesObj.question; //temp answer list List <Answer> a = new List <Answer>(); //start from first answer, end at last answer foreach (Answer answer in quesObj.answers) { a.Add(answer); } //shuffle answer ShuffleList <Answer>(a); //build question Question te = new Question(question, a); questions.Add(te); } } else { for (int i = 0; i < mc.getQuestions().Count; i++) { Question quesObj = mc.getQuestions()[i]; //temp string array, delimited by ;, first entry is the question, last entry is the correct answer string question = quesObj.question; //temp answer list List <Answer> a = new List <Answer>(); //start from first answer, end at last answer foreach (Answer answer in quesObj.answers) { a.Add(answer); } //shuffle answer ShuffleList <Answer>(a); //build question Question te = new Question(question, a); questions.Add(te); } ShuffleList <Question>(questions); } } else { warning.GetComponent <Text>().text = "Internal Error, please contact admin"; Debug.LogWarning("No searching.txt"); } }