Now that’s something I actually don’t like about the way Sam structured the damage text firing. So here’s my rewritten TakeDamage method to deal with that.
public void TakeDamage(GameObject instigator, float damage, string damageInfo = "")
{
if (isDead) return;
float oldHealth = health.value;
health.value = Mathf.Max(health.value - damage, 0);
{
if (health.value <= 0)
{
float overKill = damage - oldHealth;
string overKillText = overKill > 0 ? $"({overKill} overkill)" : "";
takeDamageText?.Invoke($"{damage} {damageInfo} {overKillText}");
Die();
AwardExperience(instigator);
}
else
{
takeDamage?.Invoke(damage);
takeDamageText?.Invoke($"{damage} {damageInfo}");
}
}
isHurt = true;
}
This will do several things:
If the character is already dead, then the method will exit immediately.
If the character is killed by the weapon, then the excess damage is calculated and expressed as overkill.