private void LogEvent(TileDestroyedEvent e) { if (e.LoggingLevel <= LoggingLevel) { Debug.Log(e.Description); } }
protected void Awake() { PauseEvent.RegisterListener(LogEvent); MenuEvent.RegisterListener(LogEvent); TileSoldEvent.RegisterListener(LogEvent); TileDestroyedEvent.RegisterListener(LogEvent); TileDamageEvent.RegisterListener(LogEvent); TileUpdateEvent.RegisterListener(LogEvent); BaseDamageEvent.RegisterListener(LogEvent); BaseDamageUIEvent.RegisterListener(LogEvent); PurchaseMadeEvent.RegisterListener(LogEvent); PartsChangedUIEvent.RegisterListener(LogEvent); EnemyRecycledEvent.RegisterListener(LogEvent); GameStartEvent.RegisterListener(LogEvent); GameOverEvent.RegisterListener(LogEvent); GameWonEvent.RegisterListener(LogEvent); FastForwardEvent.RegisterListener(LogEvent); }
private void TakeDamage(TileDamageEvent e) { Vector2Int cellLoc = (Vector2Int)grid.LocalToCell(transform.position); if (e.CellLoc == cellLoc) { CurrentHealth -= e.DamageAmount; healthBar.percentage = (float)CurrentHealth / MaxHealth; gm.UpdateHealth((Vector3Int)cellLoc); if (CurrentHealth <= 0) { TileDestroyedEvent tileKilled = new TileDestroyedEvent { Description = $"{name} tile was killed by {e.enemy.name}.", CellLoc = cellLoc }; tileKilled.TriggerEvent(); Destroy(gameObject); } } }