How to make a distance counter that updates?

So I have the basic script done in JavaScript, going to convert it to C# soon. What my script does as of right now is that it says how far two objects are from each when the game starts. What I want is that the distance updates as the object with the script moves closer or farther to the target. It displays how far something is at the beginning in the console, but it does not update as the player moves closer or farther from the object. This is the script

var other : Transform;
if (other) {
var dist = Vector3.Distance(other.position, transform.position);
print ("Distance to other: " + dist);
}

Any help would be greatly appreciated. Thank you and if anyone needs this script, feel free to use it.

Ok, so the fix was very very simple. Instead of JavaScript, I turned it into C#. THIS SCRIPT IS IN C# NOW. Instead of having the code in the Start function, I changed it to the Update function. Now whenever the player moves around, either closer or farther from the object, it shows how far it is from the other object in the console. I will make it so that the player can see there distance in the game soon. This is the script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ScriptMeter : MonoBehaviour
{
public Transform other;

private void Update()
{
    float dist = Vector3.Distance(other.position, transform.position);
    Debug.Log("Distance to other: " + dist);
}

}

feel free to use this.

Consider this:

var other : Transform;
    if (other) {
        var dist = Vector3.Distance(other.position, transform.position);
        print ("Distance to other: " + dist);
    }

Of course, instead of “print” you put your debug there. You can have anything there at “other” or change the “if” statement, etc.

Good Luck.

I think what you want is to know how to update a counter, like a visual thing that people see on the screen of the game. I would do this using a Text component.

using UnityEngine;
using UnityEngine.UI;

public class UpdateDistance : MonoBehaviour
{
  public Transform Object1;
  public Transform Object2;
  public Text Distance;

  void Update()
  {
    Distance.text = Vector3.Distance(Object1.position, Object2.position).ToString();
  }
}