public void Damage(int amount, IDamageListener listener) { Attribute shield = GetAttribute(AttributeType.SHIELD); if (shield.Value > 0) { if (listener != null) { listener.DamageListener(DamageEvents.HIT, gameObject); } shield.Value--; //PopUp.ShowText(transform.position, "1", 0, Color.blue); } else { Attribute health = GetAttribute(AttributeType.HEALTH); health.Value -= amount; if (listener == null) { return; } if (health.Value < 1) { listener.DamageListener(DamageEvents.KILL, gameObject); } else { listener.DamageListener(DamageEvents.HIT, gameObject); } //PopUp.ShowText(transform.position, amount.ToString(), 0, Color.red); } }
public void Damage(int amount, IDamageListener resultListener) { health.Value -= amount; PopUp.ShowText(transform.position, amount.ToString(), 0.5f, Color.white, PopUpAnimation.GRAVITY); if (resultListener == null) { return; } if (health.Value > 0) { resultListener.DamageListener(DamageEvents.HIT, gameObject); } else if (health.Value < 1) { resultListener.DamageListener(DamageEvents.KILL, gameObject); } }
/// <summary> /// It is used for damaging the asteroid /// </summary> /// <param name="amount">amount of damage</param> /// <param name="onDead">a function called when the asteroid is destroed</param> public void Damage(int amount, IDamageListener listener) { health.Value -= amount; if (listener != null) { listener.DamageListener(DamageEvents.HIT, gameObject); } /*PopUp popup = GameManager.ObjectPooler.Get(EntityType.DAMAGEPOPUP).GetComponent<PopUp>(); * popup.Initialize(transform.position, amount.ToString(), Color.white);*/ PopUp.ShowText(transform.position, amount.ToString(), 0.5f, Color.white, PopUpAnimation.GRAVITY); }