How to get Mouse position in Screen Space in Unity
Notes:
How to get Mouse position in Screen Space in Unity:
How to get Mouse Position:
- In Unity we have various properties and methods, which help us to get mouse position in the screen space, viewport space & world space.
How to get Mouse Position in screen space:
- screen space is the display area of the game view
- is measured in pixels
Note: screen space coordinate system
- Bottom Left corner of the screen space is considered as (0, 0, 0)
- Top Right corner of the screen space is considered as (Screen.Width, Screen.Height, 0)
Input.mousePosition:
public static Vector3 mousePosition
- returns the current mouse position in the screen space in pixels
Ex:
Debug.Log(Screen.width); // returns width of the screen in pixels
Debug.Log(Screen.height);// returns height of the screen in pixels
if (Input.GetMouseButtonUp (0)) {
Debug.Log (Input.mousePosition); // returns mouse position in pixels
}