/// <summary> /// Adds the enemy to the queue or to the game depending on how many is in game already /// </summary> /// <param name="tmp"></param> private void AddEnemy(GameObject tmp) { lock (activeKey) { if (activeEnemies.Count < Constant.maxEnemyOnScreen) { ActiveEnemies.Add(tmp); } else { lock (GameWorld.colliderKey) { ((Collider)tmp.GetComponent("Collider")).DoCollsionChecks = false; GameWorld.Instance.Colliders.Remove((Collider)tmp.GetComponent("Collider")); } enemiesWaitingToBeSpawned.Enqueue(tmp); } } }
private IEnumerator SpawnWave() { Random rand = new Random(); int intervalSoldier1 = 100; int intervalSoldier2 = 0; int intervalDogs = 0; int intervalTanks = 0; int intervalAirplanes = 0; if (wave >= 5) { intervalSoldier2 = intervalSoldier1; intervalSoldier1 -= 20; if (wave >= 7) { intervalDogs = intervalSoldier2; intervalSoldier1 -= 15; intervalSoldier2 -= 15; } if (wave >= 15) { intervalTanks = intervalDogs; intervalSoldier1 -= 10; intervalSoldier2 -= 10; intervalDogs -= 10; } if (wave >= 20) { intervalAirplanes = intervalTanks; intervalSoldier1 -= 10; intervalSoldier2 -= 10; intervalDogs -= 10; intervalTanks -= 10; } } int total = wave + (wave / 5) + (wave / 7) + (wave / 10) + (wave / 15); /* * // figure out the total amount of enemies * int numSoldiers1 = wave; * int numSoldiers2 = wave / 5; * int numDogs = wave / 7; * int numTanks = wave / 10; * int numAirplanes; * if(wave < 20) { * numAirplanes = 0; * } * else { * numAirplanes = wave / 15; * } * * * int total; * if(wave > 5) { * total = numSoldiers1 + numSoldiers2 + numDogs + numTanks + numAirplanes; * } * else { * total = numSoldiers1; * } * * List<string> types = new List<string>(); * for(int i = 0; i < numSoldiers1; i++) { * types.Add("soldier"); * } * for(int i = 0; i < numSoldiers2; i++) { * types.Add("soldier2"); * } * for (int i = 0; i < numDogs; i++) { * types.Add("Dog"); * } * for (int i = 0; i < numTanks; i++) { * // add variablilty between black and red * float num = Random.Range(0, 2); * if(num <= .5f) { * types.Add("tankRed"); * } * else { * types.Add("tankBlack"); * } * * } * * for(int i = 0; i < numAirplanes; i++) { * types.Add("airplane"); * } * * Shuffle(types); */ for (int i = 0; i < total; i++) { //string type = types[i]; string type = getTypeFromDistribution(intervalSoldier1, intervalSoldier2, intervalDogs, intervalTanks, intervalAirplanes); // get an enemy from the pool Debug.Log("Spawning: " + type); Enemy monster = Pool.GetObject(type).GetComponent <Enemy>(); monster.Spawn(LevelManager.Instance.PortalSpawn, LevelManager.Instance.GoalSpawn); ActiveEnemies.Add(monster); yield return(new WaitForSeconds(timeBetweenEnemies)); } }