Enemy Health bars help needed

I’m trying to add health bars to my enemies and I have some code written to do so, it isn’t working, I just need help to figure out how to get this working
here’s the code

using UnityEngine;
using UnityEngine.UI;
public class Target : MonoBehaviour{

    public float health = 50f;
    public Slider slider;
   

    void Start()
    {
        slider.value = health;
    }

    void update()
    {
        slider.value = health;
    }
    public void TakeDamage (float ammount)
    {
        health -= ammount;
        if(health <= 0f)
        {
            Die();
        }
        void Die()
        {
            Destroy(gameObject);
           
        }
    }

}

any help will be greatly appreciated and if you need any other code just tell me.

For starters, update() needs to be Update(). Capitalization is important.

1 Like

Thanks man That was my problem and now I fell really stupid. Thanks, this helped me a lot.