So I read through all the forums I could find about a health bar but none of them seemed to work / did it weirdly… simply looking for a rectangle that is empty when at 0 and progresses to 100 using the color red, I can make an image that is red or whatever works just trying to figure out how to do simple simple health bar that corresponds to a variable. JS preferred.
Its in the list of videos somewhere-
http://forum.unity3d.com/threads/37093-Over-7-hours-of-Unity-Training-Videos-Download-them-now!
function OnGUI(){
GUI.HorizontalScrollbar(Rect (20,40,200,20), 0, variable ,0, 100);
thats my healthbar, it works but its not red, its grey.
there might be some way to make it red
Create a 64x64 red cube image, use it as GUITexture. Set a pixel inset of 100. Then, only rest to change the width with guiTexture.pixelInset.width according to the healt.
For example…
healtBar = GUITexture; // Assign the red cube to this.
var currentLife = 100;
function Start () {
healtBar.pixelInset.width = 100;
}
function Update () {
currentLife -= 50; // Apply some damage to test…
healtBar.pixelInset.width = currentLife;
}