Health Bar

Instead of a slider, I went for a “filled bowl” style health bar.

HealthBar

and set the Image Type to filled, with a vertical method and origin at the bottom.

Inspector

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;
    }
5 Likes

Looks great reminds me of diablo

Privacy & Terms