/// <summary> /// When a player dies, this method is called. The game can consist of multiple players, and each player can have /// an effect on the game when they die. When both players die, the manager notifies interested /// listeners. /// </summary> /// <param name="player"></param> private void PlayerDied(GameObject player) { if (players.Contains(player)) { players.Remove(player); if (Players.Count <= 0) { OnAllPlayersDied?.Invoke(); } } }
/// <summary> /// Deregisters a health from the dict. /// </summary> /// <param name="health">The health to be deregistered.</param> public void DeRegister(Health health) { if (health.TryGetComponent(out Player player)) { playerHealths.Remove(health); OnPlayerDied?.Invoke(player); if (playerHealths.Count == 0) { OnAllPlayersDied?.Invoke(); } } else if (health.TryGetComponent <Enemy>(out _)) { enemyHealths.Remove(health); if (enemyHealths.Count == 0) { OnAllEnemiesDied?.Invoke(); } } }