Im making a health bar and I wanted to make the fill amount of the image the same as my Health value in my Enemyscripts script within my Enemy object. For some reason Unity doesnt recognize my code. I need help please!
C# code:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Health_bar : MonoBehaviour {
public GameObject Enemy;
// Update is called once per frame
void Update () {
Image image = GetComponent< Image >();
image.fillAmount = Enemy.GetComponent<Enemyscripts>().Health;
}
}
Enemyscripts code here:
#pragma strict
public var Health : float = 100f;
function Start () {
}
function Update () {
if (Health == 0.0) {
Destroy(gameObject);
}
}
function RemoveHealth () {
Health--;
Debug.Log(Health);
}