title: Calculate distance travelled on objects in Unity c#
body: <p>I'm currently struggling to write a dynamic script that gets the position of two objects(hands) When I don't include public variables and put the script under each of the hands it works but not when I drag them in as game objects.There is no errors. The values just don't get updated.</p>
  
  <p>This is an Oculus Rift application running on Unity 5.5 with the latest SDKs with Newton plug in.</p>
  
  <pre><code>public class calorieCounter : MonoBehaviour
  {
      public Text displayMessage;
  
      public GameObject leftHand;
      public GameObject righHand;
  
      float distanceTravelledL = 0;
      float distanceTravelledR = 0;
  
      float distanceTravelled = 0;
      Vector3 lastPosition;
  
      Vector3 lastPositionL;
      Vector3 lastPositionR;
  
      void Start()
      {
  
          lastPositionL = leftHand.transform.position;
          lastPositionR = righHand.transform.position;
          lastPosition = transform.position;
      }
  
      void Update()
      {
  
          distanceTravelledL += Vector3.Distance(transform.position, lastPositionL);
          distanceTravelledR += Vector3.Distance(transform.position, lastPositionR);
  
          lastPositionL = transform.position;
          lastPositionR = transform.position;
  
          print("Left hand distance: " + distanceTravelledL);
          displayMessage.text = ("L: " + distanceTravelledL);
  
  
          print("Right hand Distace: " + distanceTravelledR);
          print("Right hand position: " + lastPositionR);
          print("Left hand position: " + lastPositionL);
          displayMessage.text += ("R: " + distanceTravelledR);
      }
  
  }
  </code></pre>