I need to know how to get the distance between the player (first person controller) and a object such as a car (its for an objective) and I need it to auto update with every step
var distance : GUIText
var other : Transform;
if (other) {
var dist = Vector3.Distance(other.position, transform.position);
GUI.text (Rect (10, 10, 100, 20), ""Distance to other: " + dist");
}
This script has several errors: you’re messing GUIText and the GUI system. If using the GUI system, the code could be like this:
var other: Transform;
function OnGUI(){
if (other){
var dist = Vector3.Distance(other.position, transform.position);
GUI.Label(Rect(10, 10, 100, 20), "Distance to other: " + dist);
}
}