Instead of a slider, I went for a “filled bowl” style health bar.
and set the Image Type to filled, with a vertical method and origin at the bottom.
For interest, I used a delegate action to trigger the change and applied a script to the UI to control the UI.
Player Health:
public Action<float> OnHealthUpdated;
public void HealPlayer()
{
if (currentHealth < maxHealth)
{
currentHealth += 1;
}
float healthRatio = (float)currentHealth / maxHealth;
OnHealthUpdated?.Invoke(healthRatio);
}
Then, in a script I put on the image I wanted to fill:
private void Start()
{
PlayerHealth.Instance.OnHealthUpdated += PlayerHealth_OnHealthUpdated;
}
private void PlayerHealth_OnHealthUpdated(float healthRatio)
{
healthImage.fillAmount = healthRatio;
}