title: Print Unity Coordinates to a string at specified time interval
body: <p>I want to move a cube using some device and periodically (every 3 seconds) print those coordinates to a file. I am not sure how to accomplish this with my code below.  Does anybody have ideas as to how this can be done?</p>
  
  <p>Thank you!</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using System.IO;
  using UnityEngine;
  
  [RequireComponent(typeof(MeshCollider))]
  
  public class UserController : MonoBehaviour {
  
      public int speed = 20;
  
      // Update is called once per frame
      void Update()
      {
          // get input data from keyboard or controller
          float moveHorizontal = Input.GetAxis("Horizontal");
          float moveVertical = Input.GetAxis("Vertical");
  
          // update player position based on input
          Vector3 position = transform.position;
          position.x += moveHorizontal * speed * Time.deltaTime;
          position.z += moveVertical * speed * Time.deltaTime;
          transform.position = position;
      }
  
      void OnMouseDrag()
      {
          if(Input.GetMouseButton(0))
          {
              float distance_to_screen = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
              transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance_to_screen));
          }
      }
  }
  </code></pre>