protected void OnCollisionEnter2D(Collision2D col) { // alert those that are listening that we have been destroyed if (PlayerDestroyed != null) { PlayerDestroyed.Invoke(); } // then destroy the gameobject Instantiate(deathParticles, transform.position, transform.rotation); Destroy(gameObject); }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.Mouse0)) { foreach (var weapon in _section.weapons) { weapon.Shoot(); } } // If total health is lower than treshold or the ship lost all weapons if ((_section.ShipHp / _section.MaxShipHp) < criticalHealthTreshold || _section.weapons.Count == 0) { Debug.Log("Critical damage to ship! Player lost."); PlayerDestroyed?.Invoke(this, EventArgs.Empty); Destroy(this); } }
public void OnPlayerDestroyed(IPlayerDestroyedEvent evt) => PlayerDestroyed?.Invoke(evt);