Hi, so I’ve created a modified version of a script I found to create an increasing energy bar, that goes to the top about every 10 seconds. By default, it would only do it once, so Im trying to make it so it works that once it is finished, it starts again. Here is the script
var barDisplay : float = 0;
var pos : Vector2 = new Vector2(20,40);
var size : Vector2 = new Vector2(60,20);
var progressBarEmpty : Texture2D;
var progressBarFull : Texture2D;
function OnGUI()
{
// draw the background:
GUI.BeginGroup (new Rect (pos.x, pos.y, size.x, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarEmpty);
// draw the filled-in part:
GUI.BeginGroup (new Rect (0, 0, size.x * barDisplay, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);
GUI.EndGroup ();
GUI.EndGroup ();
}
function Update(){
if (barDisplay < 1 || barDisplay == 0){ //Get rid of me for the original script
barDisplay = Time.time * 0.099;
}
if (barDisplay > 1 || barDisplay == 1){ //Get rid of me for the original script
barDisplay -= 1; //Get rid of me for the original script
}
}
If you test this, it does its routine, restarts, does its routine, but then starts bugging out, and I cant work out why. It seems to barDisplay is going about 1 halfway through an increase, but I cant tell why. Hopefully you can help me.
Thanks