public void Damage() { if (!isInvincible) { health = Mathf.Clamp(health - 1f, minHealth, maxHealth); OnHit(); if (IsDead()) { onDeath.Invoke(this); FMODUnity.RuntimeManager.PlayOneShot("event:/SoundFX/Player/Death", transform.position); return; } onDamaged.Invoke(this); } }
public void Heal(float amount) { if (heal) { float healthBeforeHeal = health; health = Mathf.Clamp(health + amount, minHealth, maxHealth); health = (float)Math.Round((double)health, 2); onHealed.Invoke(this); timeLastHealed = Time.time; } }
public IEnumerator CheckHealth(float waitTime) { while (true) { yield return(new WaitForSeconds(waitTime)); if (health <= 0f) { if (isDead == false) { isDead = true; onCheckDead.Invoke(this); } } if (health > 0) { if (isDead == true) { isDead = false; } } } }