Search Unity

Mouse Click Position

Discussion in 'Scripting' started by ashwan, Apr 1, 2010.

  1. ashwan

    ashwan

    Joined:
    Mar 3, 2010
    Posts:
    21
    Hii...I am developing a traveling game. I have to move my flight(Game object) from one point to other point based on the mouse click..My question is how can I identify the co-ordinates of Mouse click position in unity so that i can move my flight to that particular position...
     
  2. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,553
    you can do a raycast, using ScreenPointToRay

    Code (csharp):
    1.  
    2.     var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    3.     var selected : RaycastHit;
    4.  
    5.     if (Physics.Raycast(ray, selected))
    6.     {
    7.         //selected.point is the 3d position of where the mouse is
    8.     }
    9.