Get the mouse position unity3

  1. ScreenPosition Vector3; // objects convert from world coordinates to screen coordinates 
     
    Vector3 mousePositionOnScreen; // get the screen to click on the screen coordinates 
     
    Vector3 mousePositionInWorld; // screen coordinates tapping the screen into a world coordinate 
     
    void Update () 
     
    { 
     
    MouseFollow (); 
     
    } 
     
    void MouseFollow () 
     
    { 
     
    // Get the mouse position in the camera (in the world), and converted into screen coordinates; 
     
    screenPosition = Camera.main.WorldToScreenPoint (transform.position); 
     
    // Get the mouse coordinates in the scene 
     
    mousePositionOnScreen = the Input. MousePosition; 
     
    // make the scene Z = mouse coordinates of the Z- 
     
    mousePositionOnScreen.z = screenPosition.z; 
     
    //The camera coordinates into world coordinates 
     
    mousePositionInWorld = Camera.main.ScreenToWorldPoint (mousePositionOnScreen); 
     
    // object follow the mouse 
     
    // transform.position = mousePositionInWorld; 
     
    // object follow the mouse X-axis moving 
     
    transform.position = new new Vector3 (mousePositionInWorld .x, transform.position.y, transform.position.z); 
     
    }

     

  2.  
     
    Go https://blog.csdn.net/agroupofruffian/article/details/78974012

Guess you like

Origin www.cnblogs.com/xiaobing-blog/p/12498927.html