![unity add custom mouse pointer unity add custom mouse pointer](https://stuartspixelgames.files.wordpress.com/2021/02/levelselect15.png)
While the X and Y values of the Vector 3 that’s returned will correspond with the screen position of the mouse, the Z value will be, by default, the same as the camera’s Z position.
UNITY ADD CUSTOM MOUSE POINTER HOW TO
How to set the depth of the mouse position
![unity add custom mouse pointer unity add custom mouse pointer](https://answers.unity.com/storage/temp/23084-texturesettings.png)
The Screen to World Point function will then return a Vector 3 value, which you can use like any other position in the scene.
![unity add custom mouse pointer unity add custom mouse pointer](https://docs.unity3d.com/uploads/Main/ToolModesExample.png)
Screen to World Point is a camera function, so you’ll need to call it from a specific camera or from the Main Camera, which is simply the first camera in the scene with a “Main Camera” tag. Like this: Vector2 mousePosition = (Input.mousePosition) Once you have the mouse’s screen coordinates, it’s possible to convert them to a real-world position, using the Screen to World Point function. So, while there is a Z value in the Mouse Position property, it’s always zero. It’s provided as a Vector 3 for compatibility reasons, allowing you to use it with functions that require a Vector 3 value. While the Mouse Position is returned as a Vector 3, it only includes X and Y values (which are the pixel coordinates on the screen). Like this: Vector3 mousePosition = Input.mousePosition This works by getting the Mouse Position property of the Input Class, which returns the pixel coordinates of the cursor on the screen as a Vector 3 value. Getting the mouse position on the screen is relatively straightforward. How to get the mouse position in the world in 2D Make a 2D projectile follow the mouse in Unity.Make a 2D object look at the mouse position.How to make a 2D object move towards the mouse’s position.How to move an object to the mouse’s position in 2D.How to get the mouse position in the world in 2D.In this article, you’ll learn how to get the mouse’s position in the scene and how you can use it to move and rotate other objects towards the cursor. Just like moving or rotating an object towards an object’s Transform position, the position of the mouse on the screen can also be used in the game, by converting it into a world position. Or, what if you want an object to look towards the mouse, turning to face it wherever it is on screen? Maybe you want an object to follow the mouse’s position? When working with 2D in Unity, you may sometimes want to make an object interact with the mouse’s position in some way.įor example, perhaps you want to place a sprite under the cursor?