public void TakeDamage(float amount, GameplayStatics.DamageType type = GameplayStatics.DamageType.Normal) { if (!m_IsInvincible) // if the target can take damage { m_CurrentHealth -= amount; // reduce your health m_CurrentHealth = Mathf.Clamp(m_CurrentHealth, 0.0f, m_MaxHealth); if (m_CurrentHealth <= 0.0f && m_OnDeath != null) { m_OnDeath.Invoke(); //if the actor is dead, call death event } if (m_OnTakeDamage != null) { m_OnTakeDamage.Invoke(amount, type); // call take damage event } var col = gameObject.GetComponent <Collider2D>(); var pos = col.bounds.center + col.bounds.extents; // pos = transform.position; if (m_DamagePopupOverride == GameplayStatics.DamageType.Null) { GameplayStatics.SpawnDmgPopup(pos + new Vector3(0, 0, -5), amount, type); } else { GameplayStatics.SpawnDmgPopup(pos + new Vector3(0, 0, -5), amount, m_DamagePopupOverride); } StartCoroutine(FlashSprite(m_HitFlashDuration)); // flash the sprite material if it can if (m_CanUseIFrames) // if the actor can use i frames { m_IsInvincible = true; // make it invincible for the iframe duration StartCoroutine(StartIFrame(m_IFrameTime)); } } }
public void Heal(float amount, GameplayStatics.DamageType type = GameplayStatics.DamageType.Heal) { m_CurrentHealth += amount; m_CurrentHealth = Mathf.Clamp(m_CurrentHealth, 0.0f, m_MaxHealth); GameplayStatics.SpawnDmgPopup(transform.position, amount, type, false); if (m_OnReceiveHeal != null) { m_OnReceiveHeal.Invoke(amount, type); } }