Ejemplo n.º 1
0
    void SpawnEnemy()
    {
        if (currentEnemyBag.Count == 0)
        {
            ShuffleAndReplenishBag(enemyPrefabBag, currentEnemyBag);
        }

        EnemyBaseClass newEnemy = currentEnemyBag[0];

        currentEnemyBag.RemoveAt(0);

        //If there is already an inactive enemy of the same type, active it and jump out
        for (int i = 0; i < inactiveEnemies.Count; i++)
        {
            if (inactiveEnemies [i].GetType() == newEnemy.GetType())
            {
                newEnemy = inactiveEnemies [i];
                activeEnemies.Add(newEnemy);
                inactiveEnemies.RemoveAt(i);
                newEnemy.Reset();
                return;
            }
        }

        //If we make it through the for loop, that means we need to make a new enemy of that type
        GameObject newEnemyObj = (GameObject)Instantiate(newEnemy.gameObject);

        //This is a bit weird, but we want to change what this is pointing to from the prefab to the new instance
        newEnemy = newEnemyObj.GetComponent <EnemyBaseClass>();

        allEnemies.Add(newEnemy);
        activeEnemies.Add(newEnemy);
//		newEnemy.Reset (); //probably don't want this, should just use Awake
    }