One easiest way to set the starting distance to be 0 is to initialize the position of the distance system gameObject to the player’s starting position. You can also use a Vector3 variable to store the player’s starting position.
There are also few ways to display the information as a text field.
Use the GUI class
public class DistanceSystem : MonoBehaviour {
public float distance;
public Transform player;
The position of the object you have this on is 500 units away from your player object at the start. Make sure they start in the same location and distance will be 0 at the start. Alternatively, you could store the starting distance in a variable, and take that away from Vector3.Distance (player.position, transform.position) when setting the distance variable.
Displaying it depends on how you want to do the HUD/GUI for your game. The best option would probably be the new UI system if you’re using 4.6 / 5, or the OnGUI system pre 4.6. Either way, there are plenty of tutorials out there for both. Have a look at these:
I upvote your reply @maccabbe
it’s simple and really good with the various solutions
but just for the gui, not bad to note the color option
like for exemple GUI.color = Color.black;