# How to display distance between Player and object in UI text? Unity 5.5

I am an beginner in Unity, with no experience in scripting. Can someone help me with a script to display distance between Player and object in UI text? Using Unity 5.5, the scene is quite simple just one room with the third person character moving around the object (CT scan). Thanks. Alex

• What have you tried doing? Where are your exact problems? Finding the distance (in 3D space?)? Displaying it as text? As is you provide too little information for a good answer – UnholySheep Jan 16 '17 at 7:28
• We could give you the code but first, you should do some research. There are lots of tutorials and articles for Unity. Try searching this and this. The first and/or the second match is perfect. – csisy Jan 16 '17 at 9:09

As @csisy pointed out, it's better to make a few researches before asking a question. Especially for basic stuff like : computing a distance between two points and displaying a text on the screen.

I haven't tested the following code :

using UnityEngine ;
using UnityEngine.UI ;

public class DistanceVisualiser : MonoBehaviour
{
// Drag & Drop the player gameobject using the inspector
public Transform objectA ;

// Drag & Drop the other object
public Transform objectB ;

// Drag & Drop the gameobject, child of a Canvas holding a Text component
public Text UIText ;

// Use LateUpdate to compute the distance **after** the player / object has moved
private void LateUpdate()
{
UIText.text = Vector3.Distance( objectA.position, objectB.position ).ToString();
}
}