public void TakeDamage(float damage) { damage -= armor.GetValue(); damage = Mathf.Clamp(damage, 0, int.MaxValue); if (damage == 0) { damage = 1; } currentHealth -= damage; if (onGetDamage != null) { onGetDamage.Invoke(currentHealth); } //Debug.Log(transform.name + " takes " + damage + " damage."); if (OnHealthChanged != null) { OnHealthChanged(maxHealth.GetValue(), currentHealth); } if (currentHealth <= 0) { if (OnHealthReachedZero != null) { OnHealthReachedZero(); } Die(); } }
public void GetDamage(int damage) { if (m_Health > 0) { m_Health -= damage; if (m_Health <= 0) { m_Health = 0; } float healthRatio = m_Health / (float)m_MaxHealth; OnGetDamage?.Invoke(healthRatio); if (m_Health == 0) { m_Explosion.transform.SetParent(null, true); m_Explosion.gameObject.SetActive(true); m_Explosion.Play(true); gameObject.SetActive(false); AudioSource.PlayClipAtPoint(m_ExplosionSound.m_Audio, transform.position, m_ExplosionSound.m_Volume); } else { m_DamageSoundPlayer.PlayOneShot(m_DamageSound.m_Audio, m_DamageSound.m_Volume); } } }
public void GetDamage(int damage, Character from) { DamageEventArgs damageargs = new DamageEventArgs(damage, from); OnGetDamage?.Invoke(this, damageargs); if (character.GetShield() != 0) { int canShield = Mathf.Min(damageargs.damage, character.GetShield()); DamageEventArgs shieldArgs = new DamageEventArgs(canShield, from); OnBlockDamage?.Invoke(this, shieldArgs); character.ChangeShield(-shieldArgs.damage); damageargs.damage -= shieldArgs.damage; if (damageargs.damage <= 0) { GetComponent <AudioSource>().clip = shieldSound; GetComponent <AudioSource>().Play(); } } if (damageargs.damage > 0) { DamageEventArgs args = new DamageEventArgs(damageargs.damage, from); OnGetDamaged?.Invoke(this, args); if (args.damage > 0) { character.ChangeHealthPoint(-args.damage); } GetComponent <AudioSource>().clip = damageSound; GetComponent <AudioSource>().Play(); } }
public virtual void TakeDamage(Damage damage) { if (currentHealth <= 0) { return; } int damageValue = Mathf.FloorToInt(damage.GetValue() * GetArmorMultiplier()); damageValue = Mathf.Clamp(damageValue, 0, int.MaxValue); currentHealth -= damageValue; var finalDamage = new Damage(damageValue, damage.GetOwner(), damage.IsCrit()); lastDamage = finalDamage; if (currentHealth <= 0) { Die(); } onGetDamage?.Invoke(finalDamage); HealthChangeEventArgs args = new HealthChangeEventArgs { healthChange = -damageValue, actor = actor, modifier = finalDamage }; OnHealthChange?.Invoke(this, args); }
private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("attack")) { OnGetDamage.Invoke(); } }
public virtual void TakeDamage(Damage damage) { if (currentHealth <= 0) { return; } int damageValue = Mathf.FloorToInt(damage.GetValue() * GetArmorMultiplier()); damageValue = Mathf.Clamp(damageValue, 0, int.MaxValue); currentHealth -= damageValue; lastDamage = damage; if (currentHealth <= 0) { Die(); } onGetDamage?.Invoke(damage); HealthChangeEventArgs args = new HealthChangeEventArgs(); args.healthChange = -damageValue; args.initiator = damage.GetOwner(); args.modifier = damage; OnHealthChange?.Invoke(this, args); }
public void Damage(float damage) { float d = CalculateDamage(damage); _currentHealth -= d; OnGetDamage?.Invoke(this, d); if (_currentHealth <= 0) { OnDeath?.Invoke(this); } }
public void GetDamage(int amount) { this.HP -= amount; if (this.HP <= 0) { this.HP = 0; } // Tigger when unit died if (!IsDead) { OnGetDamage?.Invoke(this, amount); } else if (IsDead) { OnGetDamage?.Invoke(this, amount); OnUnitDied?.Invoke(this, EventArgs.Empty); } }