Hi ! I’m new to unity. First sorry for my bad english.
I want to make a distance and a best distance travelled system . I want the distance to be displayed in the game scene and the best distance in main menu scene … Here is what i have so far.
//Score
static var score : int = 0;
static var distanceScore : int = 0;
var distanceFont : Font;
var style : GUIStyle;
// Checking distance
var previousPosition : Vector3;
var calculatedDistance : float;
function OnStart()
{
}
function Awake()
{
previousPosition = transform.position;
}
function FixedUpdate () {
}
function Update()
{
calculatedDistance += (transform.position - previousPosition).magnitude;
previousPosition = transform.position;
distanceScore = Mathf.Round(calculatedDistance/0.1);
score = distanceScore;
}
function OnGUI()
{
GUI.Label(Rect(0, 50, 200, 30), "Distance: "+score, style);
}