private void LoadRandomQAToGeneral() { const int mainQuestionCount = 13; int[] randomArray = new int[mainQuestionCount]; int length = 0; int randomIndex; //Get SIX (static) random different QA set from the mainQuestionSource for (int i = 0; i < 6; i++) { //While the random index is exists in the random index array do { //Keep random the index randomIndex = Random.Range(0, mainQuestionCount); } while (IsExists(randomArray, randomIndex)); //Add the new randomIndex to the random index array randomArray[length++] = randomIndex; //Add the QASetSource to the randomMainQASet list randomMainQASet.Add(mainQuestionsSource[randomIndex]); } // Add the NPCController's Script component to the general GameObject npc = general.AddComponent <NPCController>(); //Change the settings of this component by using the AddQA function npc.AddQA(randomMainQASet); }
private void LoadRandomQAToSoldiers() { Debug.Log("Run GameManager"); const int maxSubQuestionCount = 7; //Random the count of sub question in one scene int subQuestionCount = Random.Range(1, 5); Debug.Log("Sub question:" + subQuestionCount); int length = 0; int randomIndex; int[] randomArray = new int[subQuestionCount]; //Get subQuestionCount random different QA set from the subQuestionSource for (int i = 0; i < subQuestionCount; i++) { //While the random index is exists in the random index array do { //Keep randomizing the index randomIndex = Random.Range(0, maxSubQuestionCount); } while (IsExists(randomArray, randomIndex)); //Add the new randomIndex to the random index array randomArray[length++] = randomIndex; //Add the QASetSource to the randomSubQASet list randomSubQASet.Add(subQuestionsSource[randomIndex]); } //Find all the soldies GameObject soldiers = GameObject.FindGameObjectsWithTag("Soldier"); //Check if the soldier count is smaller than number of sub QA Set if (soldiers.Length < randomSubQASet.Count) { return; //Then we don't have enough soldies to be added by QA } int[] tempArray = new int[subQuestionCount]; length = 0; //Add all the SubQASet to the random soldier in soldiers list foreach (var set in randomSubQASet) { //While the random index is exists in the random index array do { //Keep randomizing the index randomIndex = Random.Range(0, soldiers.Length); } while (IsExists(tempArray, randomIndex)); //Add the new randomIndex to the random index array tempArray[length++] = randomIndex; // Add the NPCController's Script component to the soldier GameObject npc = soldiers[randomIndex].AddComponent <NPCController>(); //Change the settings of this component by using the AddQA function npc.AddQA(set); } }