private void SendEventPlayerHit(float amount) { PlayerHitEventArgs playerHitEventArgs = new PlayerHitEventArgs(); playerHitEventArgs.damage_amount = amount; if (OnPlayerHit != null) { OnPlayerHit(this, playerHitEventArgs); } }
//handling the event of being hit. If health>0 (i.e. alive) lowers health. If it caused death, calls "Death()" private void EventHandler_OnPlayerHit(object sender, PlayerHitEventArgs e) { if (health > 0) { health -= e.damage_amount; UpdateTextHealth(); if (health <= 0 && ALIVE) { ALIVE = false; Death(); } } //Do more Stuff }
public virtual void Damage(float damage, int damagerId) { if (!alive) { return; } float damageToShip = 0; damageToShip = DamageShield(damage); damageToShip = DamageArmor(damageToShip); currentHealth -= damageToShip; if (currentHealth <= 0) { alive = false; KillShip(damagerId); } PlayerHitEventArgs args = new PlayerHitEventArgs { playerId = 1, damageDelt = damageToShip }; GameEventSystem.PublishEvent(typeof(PlayerDamagedSubscriber), args); if (damageToShip > 0) InfoBlurbManager.CreateInfoBlurb(this.transform.position, "" + damageToShip.ToString("0.0"), Color.red); }