Videogames Development – Unity – Get Mouse Position
SCRIPT
MAIN TOP MENU> ASSETS> CREATE> Javascript, type the name ‘GetMousePosition’
Assets> GetMousePosition> Inspector> ‘Open…’ button
Write:
#pragma strict function Start () { } function Update () { var mouse = Input.mousePosition; Debug.Log(mouse); }
Create an Object inside the Hierarchy ‘MyObject’
Assets> DRAG AND DROP ‘GetMousePosition’ script over Hierarchy> MyObject
Play> move the mouse, look at the BOTTOM OF THE SCREEN, you will see the coordinates as: (536.0, 583.0, 0.0)
The current mouse position in pixel coordinates. (Read Only)
The bottom-left of the screen or window is at (0, 0).
The top-right of the screen or window is at (Screen.width, Screen.height).