Hey, im trying to make a bar which will show how far are you from the end im not sure how to do it… kinda stuck.
i got how to see the distance bitween 2 objects and how to make the progress bar but to make them fit each other is where i got stuck :?
var other : Transform;
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()
{
var dist = Vector3.Distance(other.position, transform.position);
print ("Distance to other: " + dist);
// 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 = dist;
}
and yeah i know the last line is not good thats what im trying to fix tho.
if the world is linear (aka you can start at 0 and work to 100% of the level) then you want to take the % of the distance that is done, and fill the bar that way
sorry for being annoying.
i dont really know how to do that, im just a beginner.
the scene is in side scrolling so you can go both x and -x and jump.
so if i make 2 gameObjects 1 for start and one for the ending, how i will make the distance between thos into percent?
thanks.
var other : Transform;
var barDisplay : float = 0;
var pos : Vector2 = new Vector2(20,40);
var size : Vector2 = new Vector2(60,20);
var progressBarEmpty : Texture2D;
var progressBarFull : Texture2D;
var totalDistance : float = 0;
var startPoint : GameObject;
var endPoint : GameObject;
var Start(){
totalDistance = Math.Abs(endPoint.transform.position.x - startPoint.transform.position.x);
}
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()
{
var dist = Vector3.Distance(other.position, transform.position);
print ("Distance to other: " + dist);
// 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 = dist/totalDistance;
}
your awesome for these replays but unfortuantly it doesnt works right
its backwards and it starts from 1.6 even tho im in the same place as the start point.
but thanks for leading me closer you rock!