- Home /
how to display distance in scene
how do i display the distance find and display it on the scene.
var obj1 : Transform;
var obj2 : Transform;
function Update () {
var distance:float = Vector3.Distance(obj1.position, obj2.position);
Debug.Log("distance =" + distance +"Km");
On the screen, anythings will do, see what can you think off,just show me how ^^
Answer by flamy · Feb 03, 2012 at 10:00 AM
var obj1 : Transform;
var obj2 : Transform;
var dist : float;
function Update () {
dist= Vector3.Distance(obj1.position, obj2.position);
}
function OnGUI()
{
GUI.Label(""+dist);
}
yea it work addited with GUI.Label(Rect(1,2,3,4),dist+""); thx
Can you tell me the Vector3.Distance is measure in what, example..$$anonymous$$m ,m ,cm or somethings else ??
by default units is in meter. but you can edit it in project setting to be wat ever you want!
actually i am going to display this distance in my flight menu. displaying the distance between my helicopter and base point. i want to ask you another things. is the distance also measuring the height. as in if helicopter fly height increase in Y-axis, will it increase in distance and will it increase distance when move in X-axis..
you are using Vector3.Distance () so obviously it will take in to account both movement in x axis and movement in y axis.. both these will reflect in the distance!
Answer by senad · Feb 03, 2012 at 09:41 AM
Build a GUI with a text label. Instead of using Debug.Log you put the same string in the text label.
If you do not know how to build and use GUIs, read it up in the manual.
:)
Your answer
Follow this Question
Related Questions
Help in Calculate Point to Point distance 0 Answers
Should i use terrain generation or make it myself for android? 0 Answers
Script Conversion JS to C# 3 Answers
how to script a timed GUI Label into my script 1 Answer
Vector3.Distance function unclear 2 Answers