I know it’s asked a lot because I’ve looked around for answers but can’t quite fix this issue.
It’s the same code you have probably seen floating around before and I can’t work out how to convert it from filling up with time to filling up when pickups are picked up.
var pickupTarget : int;
var currentPickups : int;
var barDisplay : float = 0;
var pos : Vector2 = new Vector2(20,40);
var size : Vector2 = new Vector2(120,40);
var progressBarEmpty : Texture2D;
var progressBarFull : Texture2D;
var skin : GUISkin;
function Start()
{
GUI.skin = skin;
pickupTarget = 100;
}
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()
{
// for this example, the bar display is linked to the current time,
// however you would set this value based on your desired display
// eg, the loading progress, the player's health, or whatever.
barDisplay = currentPickups/pickupTarget;
if (barDisplay >=1)
{
barDisplay =1;
}
}
I’ve tried a few things with the update but i’m clutching at straws. When the player picks up an object it adds one to the ‘current pickups’. I want the bar to fill when 'pickuptarget# has been reached (when 100 pickups are collected the bar is full). Also there are over 100 pickups so thats why i have that limiter thing at the very end.
what glaring obvious mistake have I made here?
thanks guys!