IEnumerator spawn() //same as spawnerclass just now any one can spawn randomly { string word = file.getRandomWord(); numberOfTimesPlayed.text = PlayerPrefs.GetInt("played").ToString(); //set the number of time the game has been played Transform x; for (int i = 0; i < word.Length; i++) //set the speeled out word { text[i].text = char.ToUpper(word[i]).ToString(); } for (int i = 0; i < word.Length; i++) { yield return(new WaitForSeconds(interval)); //initial wait int temp = char.ToUpper(word[i]) - 65; int turn = Random.Range(0, 3); if (turn == 0) // if it's 1st spawnwers turn to spawn the valid letter { StartCoroutine(spawn2(temp)); //ask spawner 2 to spawn random letter after a random wait StartCoroutine(spawn3(temp)); //ask spawner 3 to spawn random letter after a random wait yield return(new WaitForSeconds(Random.Range(0f, interval))); //wait for random time x = Instantiate(letters[temp], sp1.position, Quaternion.identity) as Transform; //spawn the valid letter x.gameObject.tag = "letter"; // tag it "letter" for laser collider } else if (turn == 1) //similarily if spawner 2 has to spawn valid letter { StartCoroutine(spawn1(temp)); StartCoroutine(spawn3(temp)); yield return(new WaitForSeconds(Random.Range(0f, interval))); x = Instantiate(letters[temp], sp2.position, Quaternion.identity) as Transform; x.gameObject.tag = "letter"; } else //similarily if spawner 2 has to spawn valid letter { StartCoroutine(spawn2(temp)); StartCoroutine(spawn1(temp)); yield return(new WaitForSeconds(Random.Range(0f, interval))); x = Instantiate(letters[temp], sp3.position, Quaternion.identity) as Transform; x.gameObject.tag = "letter"; } } yield return(new WaitForSeconds(3f)); //wait for game to finish Camera.main.transform.GetComponent <canvasManagement>().showWin(); //show win screen }
IEnumerator spawn() { string word = file.getRandomWord(); //get random word int letterExceptValidOne; //to store letter other than the one to be shot numberOfTimesPlayed.text = PlayerPrefs.GetInt("played").ToString(); //show number of time the game has been played Transform x; // to store valid instantiated letter for (int i = 0; i < word.Length; i++) //show the word being spelled out { text[i].text = char.ToUpper(word[i]).ToString(); } for (int i = 0; i < word.Length; i++) //number of time that letters are going to get spawned { yield return(new WaitForSeconds(interval)); //initial wait int temp = char.ToUpper(word[i]) - 65; //temp contains the index of letter in alphabet int turn = Random.Range(0, 3); // to randomly select spawner for valid letter if (turn == 0) // if 1st spawner spawns { x = Instantiate(letters[temp], sp1.position, Quaternion.identity) as Transform; //spawn valid letter x.gameObject.tag = "letter"; //tag it for laser collider //spawn random letter other than valid one from other two spawner letterExceptValidOne = Random.Range(0, 26); while (letterExceptValidOne == temp) { letterExceptValidOne = Random.Range(0, 26); } Instantiate(letters[letterExceptValidOne], sp2.position, Quaternion.identity); letterExceptValidOne = Random.Range(0, 26); while (letterExceptValidOne == temp) { letterExceptValidOne = Random.Range(0, 26); } Instantiate(letters[letterExceptValidOne], sp3.position, Quaternion.identity); } else if (turn == 1) //similarily is spawnwer 2 gets selected { x = Instantiate(letters[temp], sp2.position, Quaternion.identity) as Transform; x.gameObject.tag = "letter"; letterExceptValidOne = Random.Range(0, 26); while (letterExceptValidOne == temp) { letterExceptValidOne = Random.Range(0, 26); } Instantiate(letters[letterExceptValidOne], sp1.position, Quaternion.identity); letterExceptValidOne = Random.Range(0, 26); while (letterExceptValidOne == temp) { letterExceptValidOne = Random.Range(0, 26); } Instantiate(letters[letterExceptValidOne], sp3.position, Quaternion.identity); } else //similarily if spawner 3 gets selected { x = Instantiate(letters[temp], sp3.position, Quaternion.identity) as Transform; x.gameObject.tag = "letter"; letterExceptValidOne = Random.Range(0, 26); while (letterExceptValidOne == temp) { letterExceptValidOne = Random.Range(0, 26); } Instantiate(letters[letterExceptValidOne], sp1.position, Quaternion.identity); letterExceptValidOne = Random.Range(0, 26); while (letterExceptValidOne == temp) { letterExceptValidOne = Random.Range(0, 26); } Instantiate(letters[letterExceptValidOne], sp2.position, Quaternion.identity); } } yield return(new WaitForSeconds(3f)); //wait for game to get finished Camera.main.transform.GetComponent <canvasManagement>().showWin(); //show win }