//Event Method private void PublishEnemyKilledEvent() { EnemyKilledEvent?.Invoke(this); // (this) keyword refers to the current instant // the (?) is the null check operator }
private void OnTriggerEnter2D(Collider2D collision) { ILife life = collision.transform.GetComponentInParent <ILife>(); if (life != null && collision.transform.parent == _targetTransform.transform) { if ((life.Health <= 0 || life.CurrentLifeForce <= 0) && collision.tag == "Enemy") { Destroy(collision.transform.parent.gameObject); EnemyKilledEv.Invoke(true); } if (collision.tag == "Enemy" || collision.tag == "Player") { this.gameObject.SetActive(false); } } }
public void OnEnemyKilled(Enemy enemyData) { enemyKilledEvent.Invoke(enemyData); enemiesKilledThisRound += 1; }
private void AddScore() { EnemyKilledEvent?.Invoke(); }
protected virtual void Die() { EnemyKilledEvent?.Invoke(this); Destroy(gameObject); }