Im making a health bar and in the update function I set the image.fillAmount to be a variable I created. For some reason the health bar stays at 100 %. Can you tell me please why this happens please!
Health_bar script:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Health_bar : MonoBehaviour
{
public GameObject Enemy;
// Update is called once per frame
void FixedUpdate()
{
float EnemyHealth = Enemy.GetComponent<Enemyscripts>().Health;
Image image = GetComponent<Image>();
image.fillAmount = (EnemyHealth);
Debug.Log("Health : " + EnemyHealth);
}
}
By the way the GetComponent().Health is a variable in another script. Also the log is displayed with updated health every time health is lost. I tried Update() function but it didnt work either.