Question by
little buster · May 23, 2016 at 02:34 PM ·
multiplehealth
Im tying to make independent health bars for each entity the code is attached to.
using UnityEngine; using System.Collections; using UnityEngine.UI; using System;
public class HealthForAll : MonoBehaviour {
Image healthBar;
private int maxHealth;
private int health;
static Fighter Fighter;
// Use this for initialization
void Start ()
{
healthBar = GetComponent<Image>();
Fighter = this;
}
//
void Awake()
{
Fighter = this;
health = maxHealth;
}
// Update is called once per frame
void Update ()
{
healthBar.fillAmount = Mathf.Lerp(healthBar.fillAmount, (float)Fighter.health/(float)Fighter.maxHealth, 0.075f);
}
}
Comment