Don't heal beyond maximum health

I had taken care of this already using a Clamp() operation:

public void HealPlayer(int healthAmount)
{
    currentHealth = Mathf.Clamp(currentHealth + healthAmount,
                                currentHealth, maxHealth);
    UpdateHealthSlider();
}

Come to think of it, if one were going to stop hearts being consumed when already at full health, it might actually be better to use an if() statement instead…
Otherwise, it might be just a fraction more efficient to us the library function…

Privacy & Terms