title: Get transform from mouse click position
body: <p>Tried this a million ways, always get conversion errors. I am simply clicking around, against a plane, would like mouse position at click to get pumped into a transform variable so that my character walks towards that point. I'm using <code>var target: Transform;</code> to define where the character moves. How can I extract that type of variable from a click in world space, which will intersect with a plane (or anything)?</p>
  
  <pre><code>var WalkingSpeed = .05;
  
  // The target marker.
  var target: Transform;
  
  // Speed in units per sec.
  var speed: float;
  
  static var mousePos : Vector3;
  
  function Update() {
      // get distance between objects current position and the target position
      var distance = Vector3.Distance (target.transform.position, transform.position);
  
      if(distance &gt; 0) {
          // we are still not at the target, do walking animation
          animation["walk"].speed = 1;    // set speed of animation
          animation.CrossFade("walk");    // actually play the animation
      } else {
          animation["idle"].speed = 1;    // set speed of animation
          animation.CrossFade("idle");    // actually play the animation
      }
      //Debug.Log(distance);
  
      // The step size is equal to speed times frame time.
      var step = speed * Time.deltaTime;
  
      // Move our position a step closer to the target.
      transform.position = Vector3.MoveTowards(transform.position, target.position, step);
  
      // Also rotate towards the point
      var targetDir = target.position - transform.position;
      var newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0);
      // Move our position a step closer to the target.
      transform.rotation = Quaternion.LookRotation(newDir);
  
      Debug.DrawRay(transform.position, newDir, Color.red);   // draw something showing direction (for debug)
  
      // on click, set new target position
      if (Input.GetMouseButton(0)) {
          var posVec = Input.mousePosition;
          posVec.z = transform.position.z - Camera.main.transform.position.z;
          target = Camera.main.ScreenToWorldPoint(posVec);
  
      }
  }
  </code></pre>
  
  <p>This one in particular throws cannot convert vector3 to transform</p>