/// <summary> /// /// </summary> /// <param name="cause"></param> /// <param name="damage"></param> public void TakeDamage(Damager cause, int damage) { if (!CanBeHit(cause)) { return; } CurrentHealth = Mathf.Max(0, CurrentHealth - damage); if (CurrentHealth > 0) { Hit(); } else { Die(); } }
/// <summary> /// /// </summary> /// <param name="cause"></param> /// <returns></returns> protected bool CanBeHit(Damager cause) { if (Invulnerable) { return(false); } if (Immune(cause)) { return(false); } if (cause.Dodgeable && Dodging) { return(false); } if (CurrentHitTimeout > 0) { return(false); } return(true); }
/// <summary> /// /// </summary> /// <param name="cause"></param> /// <returns></returns> protected override bool Immune(Damager cause) { return(!cause.GetComponent <Explosion>()); }
/// <summary> /// /// </summary> /// <param name="cause"></param> /// <returns></returns> protected virtual bool Immune(Damager cause) { return(false); }