private void OnUnitDied(UnitDiedMessage msg) { if (msg.DeadUnit == _unit) { UnregisterEventListeners(); } }
/// <summary> /// Called when unit has died in the scene. unregisters listening events that are used by living unit /// starts listening unitrespawn timer so it can be shown in the UI /// </summary> /// <param name="msg"> contains information about which unit died in the scene </param> private void OnUnitDied(UnitDiedMessage msg) { if (msg.DeadUnit == _unit) { UnregisterEventListeners(); _unitRespawnTimerSubscription = GameManager.Instance.MessageBus.Subscribe <UnitRespawnTimerMessage>(UnitRespawnTimer); } }
private void OnUnitDied(UnitDiedMessage msg) { if (msg.DeadUnit == _unit) { // UnregisterEventListeners(); gameObject.SetActive(false); } }
/// <summary> /// Triggered when an UnitDiedMessage is sent to messagebus, it is then inspected /// if the unit was PlayerUnit refreshes the UI /// </summary> /// <param name="msg"></param> private void PlayerDied(UnitDiedMessage msg) { if (msg.DeadUnit is PlayerUnit) { GameManager.Instance.PlayerDied(); SetText(); } }
/// <summary> /// Called when a unit dies. /// </summary> /// <param name="msg">A unit died message</param> public void OnUnitDied(UnitDiedMessage msg) { // Only if the unit of the message is the // referenced unit, handle unit death if (msg.DeadUnit == unit) { //msg.PrintMessage(); isDead = true; respawnCurrentSecond = (int)unit.RemainingRespawnTime + 1; } }
/// <summary> /// Adds the unit contained in the message to deadUnits and adds respawn time to deadUnitTimers /// the respawn time depends if the unit that died was player or enemy /// </summary> /// <param name="msg"></param> private void OnUnitDied(UnitDiedMessage msg) { if (msg.DeadUnit is PlayerUnit) { _deadUnits.Add(msg.DeadUnit); _deadUnitTimers.Add(_playerRespawnTime); } else { _deadUnits.Add(msg.DeadUnit); _deadUnitTimers.Add(_enemyRespawnTime); } }
/// <summary> /// The class listens to OnUnitDied messages and acts depending on /// if it was the player's tank or an enemy tank that died. /// I added the actual death mechanics (resetting health and /// moving the tanks to respawn areas) in the Unit class. /// </summary> /// <param name="msg"></param> private void OnUnitDied(UnitDiedMessage msg) { if (msg.DeadUnit is PlayerUnit) { _playerRemainingLives--; _remainingLivesText.text = string.Format("Remaining lives " + _playerRemainingLives); WinOrLose(); } if (msg.DeadUnit is EnemyUnit) { _score += _scorePerEnemyTank; UpdateScore(); } }
/// <summary> /// Waits call to add units to deadlist /// </summary> /// <param name="msg">UnitDiedMessage</param> private void OnUnitDied(UnitDiedMessage msg) { if (msg.DeadUnit is PlayerUnit) { if (msg.DeadUnit.Health.CurrentLives <= 0) { Debug.Log("Lost"); GameManager.Instance.WinOrLose = false; GameManager.Instance.EndGame(false); return; } _deadTanks.Add(msg.DeadUnit); _timers.Add(_playerTankRespawnTime); } else { _deadTanks.Add(msg.DeadUnit); _timers.Add(_enemyTankRespawnTime); } }
private void OnUnitDied(UnitDiedMessage msg) { if (msg.DeadUnit == _unit && IsEnemy) { } }