Hello - I want my health bar to decrease proportionately with the amount of player vitality. However I can’t seem to link the player’s health to the health bar correctly - on using this code which seems to have worked for some people I have been given this error, and I just can’t work out how to change it.
Here’s the code:
var energyBar : GUIStyle ;
var bgImage : Texture2D;
var fgImage : Texture2D;
static var playerEnergy = 1.0;
var maxHealth : float = 100;
var curHealth : float = 100;
var percentHealth : Number = curHealth / maxHealth;
function Start() {
}
function Update() {
}
function OnGUI () {
GUI.BeginGroup (Rect (10,10,256,32));
GUI.Box (Rect (0,0,256,32), bgImage, energyBar);
GUI.BeginGroup (Rect (0,0,playerEnergy * 256, 32));
GUI.Box (Rect (0,0,256,32), fgImage, energyBar);
GUI.EndGroup ();
GUI.EndGroup ();
}
function updateHealthBar () : void
{
percentHealth = curHealth / maxHealth;
fgImage.ScaleX = percentHealth;
}
If anyone has the time to help, it would be so appreciated.
Thanks in advance, Laurien
Thanks - I'll give that a go!
– laurienash