I know there’ll be a performance hit with using FindObjectsOfType each frame, but I didn’t like the idea of the LevelController been “controlled”, I feel it should be doing the “controlling”.
So I did this:
public class LevelController : MonoBehaviour
{
private int numberOfAttackers = 0;
private GameTimer gameTimer;
// Start is called before the first frame update
void Start()
{
gameTimer = FindObjectOfType<GameTimer>();
}
// Update is called once per frame
void Update()
{
if (gameTimer.HasTimerFinished())
{
AttackerSpawner[] attackerSpawners = FindObjectsOfType<AttackerSpawner>();
foreach(AttackerSpawner spawner in attackerSpawners)
{
spawner.StopSpawning();
}
}
int numberOfAttackers = FindObjectsOfType<Attacker>().Length;
if ((numberOfAttackers == 0) && (gameTimer.HasTimerFinished()))
{
Debug.Log("End Level Now");
}
}
}