- Home /
 
Variable is assigned but never used for ScreenPointToRay
I'm trying to use the mouse cursor as a target for a look at IK asset I bought from the store but I'm having trouble getting all the data I apparently need. Here is the script:
 void FixedUpdate () {
 
         Plane playerPlane = new Plane(Vector3.forward, transform.position);
 
         Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 
         float hitdist = 0.0f;
 
         if(playerPlane.Raycast (ray, out hitdist)){
 
             Vector3 targetPoint = ray.GetPoint(hitdist);
 
         }
     
     }
 
               Unity is saying " The variable 'targetPoint' is assigned but its value is never used". So, what more information do I need here? Does targetPoint need to be a Transform?
Answer by psyydack · Jun 14, 2014 at 03:08 AM
It's not an Error just a Warning message.
http://docs.unity3d.com/ScriptReference/Debug.LogWarning.html
Try this (this code is in JS):
 private var targetPlane : Plane;
 
 function Start(){
   targetPlane = Plane(Vector3().up, 0);
 }
 
 function Update () {
    //player look direction
    var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    var dist : float;
    if(targetPlane.Raycast(ray, dist)){
        var pos = ray.GetPoint(dist);
        transform.LookAt(pos, Vector3().up);
     }
 }
 
               Look this thread too http://forum.unity3d.com/threads/need-help-with-target-mouse-x-and-y-positon.41077/
Your answer
 
             Follow this Question
Related Questions
Get Vector3 of Position Clicked on Plane 1 Answer
Instantiate at raycast position 1 Answer
Why does ScreenPointToRay bug when called from IEnumerators? 1 Answer
Unity Mouse Position Raycasting from Point 0 Answers
Add Force based on Raycast 1 Answer