/// <summary> /// Removes any enemies that have been flagged as not alive /// </summary> void CleanupEnemies() { for (int i = 0; i < gameEnemies.Length; ++i) { if (gameEnemies[i].activeInHierarchy && !gameEnemies[i].GetComponent <Enemy>().Alive) { //Remove enemy from big list of enemies zoneEnemies.Remove(gameEnemies[i]); if (currentEncounterType == Encounter.SpecialEncounters.PrincessRescue && zoneEnemies.Count == 0) { //Tell the princess that she's saved GameObject.Find("Princess").GetComponent <Princess>().SavePrincess(); } //Remove from list of interactive NPCs for (int j = 0; j < textMan.InteractiveNPCs.Length; ++j) { if (textMan.InteractiveNPCs[j] == gameEnemies[i]) { textMan.InteractiveNPCs[j] = null; } } //Remove enemy from list of encounter enemies if it's there if (encounterEnemies.Contains(gameEnemies[i])) { encounterEnemies.Remove(gameEnemies[i]); } //Remove enemy from array of enemies surrounding the player if it's there for (int j = 0; j < 6; ++j) { if (surroundingGridOccupants[j] == gameEnemies[i]) { surroundingGridOccupants[j] = null; } } //Check to see if any encounter enemies had it as their attack target Enemy e; for (int j = 0; j < encounterEnemies.Count; ++j) { e = encounterEnemies[j].GetComponent <Enemy>(); if (e.AttackTarget == gameEnemies[i]) { e.AttackTarget = null; e.AttackTarget = GetNewAttackTarget(e.faction); } } //Destroy gameobject //Destroy(gameEnemies[i]);//DEPRECATED -- Now we're just setting to inactive so that the enemy can respawn on death //Tell the flag manager whether or not the enemy was a human flags.EnemyKilled(gameEnemies[i].GetComponent <Enemy>().faction == Enemy.EnemyFaction.Human); //Set to null //gameEnemies[i] = null;//Again, only doing inactive stuff now gameEnemies[i].SetActive(false); } } }