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); } } }
private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("attack")) { OnGetDamage.Invoke(); } }
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 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); } }