Esempio n. 1
0
    public void spawn()
    {
        GameObject prefab;

        WaveManager.Instance.EnemyPrefabs.TryGetValue(type, out prefab); //Get the prefab of the enemy

        Enemy enemy;

        for (int i = 0; i < amount; i++)                                                 //Iterate through each enemy
        {
            SpawnLocation randomLocation = WaveManager.Instance.getRandomSpawnPos(Type); //Get a spawn location
            //Get the enemy from the pool
            enemy = SimplePool.Spawn(prefab, randomLocation.Position, Quaternion.identity).GetComponent <Enemy>();

            //Set enemy properties
            enemy.weaponPrefab = WaveManager.Instance.getEnemyWeapon(type, level);

            int lvl = (int)level;

            float multiplier = 1 + (lvl / 10); //Get the multiplier

            Color clr = Color.red;
            if ((int)level <= WaveManager.Instance.EnemyLevelColors.Length)
            {
                clr = WaveManager.Instance.EnemyLevelColors[lvl];
            }

            enemy.SetColor(clr);

            //Apply the multiplier to the enemy's stats
            enemy.Speed     = multiplier;
            enemy.TurnSpeed = multiplier;

            /*enemy.initialHealth = initialHealth;
             * enemy.Reward = rewardAmount;*/

            int[] healthPerLevel = { 1, 3, 5, 10, 20 };
            int[] rewardPerLevel = { 1, 3, 5, 10, 25 };

            enemy.initialHealth = healthPerLevel[lvl];
            enemy.Reward        = rewardPerLevel[lvl];

            //Spawn the enemy
            enemy.Spawn(randomLocation.Position, Quaternion.identity);

            randomLocation.Use(); //Use the random location
        }
        spawned = true;
    }