/// <summary> /// Generate a zombie and add him to the list /// </summary> void addZombie() { int newDifficulty = Difficulty_difficulty.onSpawn(); //what the difficulty currently is if (int_difficulty != newDifficulty) //if the difficulty has changed { int_difficulty = newDifficulty; numWords = 1; } GameObject goZ = (GameObject)Instantiate(Resources.Load("CommonZombie")); //Instantiate the zombie prefab from resources //Assign to an enemyManager //1:Randomly choose an enemyManager es = GameObject.FindGameObjectsWithTag("Spawner"); //Es now contains all of the enemy spawners int emi = (int)Random.Range(0, es.Length); //stands for enemy manager index //2:Set parent child relationship Transform pT = es[emi].transform; //pt stands for parent transform goZ.transform.parent = pT; Vector3 spawnPos = pT.position; spawnPos.x += Random.Range(-pT.lossyScale.x / 2, pT.lossyScale.x / 2); spawnPos.y += Random.Range(-pT.lossyScale.y / 2, pT.lossyScale.y / 2); ///goZ.transform.position.x += es[emi].transform.localScale.x; ///goZ.transform.position.y += es[emi].transform.localScale.y; goZ.transform.position = spawnPos; ZombieAI ZAI = goZ.GetComponent <ZombieAI>(); //get words for this zombie. Upgrades knows the difficulty settting so it can effectively determine //how many words to give ///numWords = Difficulty_difficulty.getNumWords(); ZAI.setWords(dictionary.pickWords(Difficulty_difficulty.WordLength, Difficulty_difficulty.NumWords * 10)); ZAI.setStats(int_difficulty, numWords); }