Need help here, I am trying to do a distance progress bar, and I found a good tutorial from www.unity3dStudent.com about creating distance progress bar, the problem is they teach how to do it using OnGUI function, I would like to used 3D game object for my distance progress bar. How would I do it, I try to change the code from the tutorial and I’m kindda stuck and dont know what to do next.
Below is what I’ve done so far :
#pragma strict
//distance on track//
public var startPoint : Transform;
public var endPoint : Transform;
public var playerPos : Transform;
public var totalDistance : float;
public var playerDistance : float;
public var playerProgress : float;
//distance on track//
//distance on bar//
public var startIcon : Transform;
public var endIcon : Transform;
public var iconPos : Transform;
public var iconTotal : float;
public var iconDistance : float;
public var iconProgress : float;
//distance on bar//
function Update ()
{
totalDistance = endPoint.position.x - startPoint.position.x;
playerDistance = playerPos.position.x - startPoint.position.x;
playerProgress = playerDistance / totalDistance * 100;
iconTotal = endIcon.position.x - startIcon.position.x;
iconDistance = iconPos.position.x - startIcon.position.x;
iconProgress = iconProgress / iconDistance * 100;
}
I know that you need to check distance between the track start point and end point, and for you distance progress bar you need to check the distance between the progress bar. Now how do I tell my icon progress position to move with the player position and let my progress icon know the distance between the progress bar is the same as the track.
//Take the max distance:
var maxDistance = Vector3.Distance(startPos, endPos)
//Then the players distance:
var playerDistance = Vector3.Distance(playerPos, endPos)
//Divide the players distance by the maximum distance.
var distanceAmount = maxDistance / playerDistance
distanceAmount is a normalized amount (between 0-1), you can use this just like a percentage to move your icon.
Sorry, can you elaborate more on your code, I have to put this inside the icon right? and the startPos and endPos is my “startPoint endPoint” or my “startIcon endIcon”?
And how do I made my icon move as my character move as well. Sorry for asking alot, still learning.
I don’t know much about coding(I code, but don’t really do advanced stuff), but maybe have it where the endpoint has a raycast on the player, and the closer the player gets to it the GUI moves forward/backwards?