Last hit not showing in the damage display

When calling takeDamage after checking it the character is dead, doesn’t show the damage this time.
So, I add a call inside the “if” to show the last hit damage amount.

        public void TakeDamage(GameObject instigator, float damage)
        {
            Debug.Log($"{gameObject.name} took damage: {damage}");

            healthPoints.value = Mathf.Max(healthPoints.value - damage, 0.0f);

            if (healthPoints.value == 0.0f)
            {
                takeDamage.Invoke(damage);
                Die();
                AwardExperience(instigator);
            }
            else
            {
            takeDamage.Invoke(damage);
            }
        }

Since you are invoking the event if the health is 0 and when it’s not, you don’t need the else. Just invoke the event outside of the if’s

public void TakeDamage(GameObject instigator, float damage)
{
    Debug.Log($"{gameObject.name} took damage: {damage}");

    healthPoints.value = Mathf.Max(healthPoints.value - damage, 0.0f);

    takeDamage.Invoke(damage);
    if (healthPoints.value == 0.0f)
    {
        Die();
        AwardExperience(instigator);
    }
}
2 Likes

Thank you, even more consistent.

Privacy & Terms