[Unity]Obtain and display mouse coordinates
This time, we would like to acquire the coordinates of the mouse and display those acquired coordinates in the Text of the UI.
First, create a new script with an arbitrary name.
Attach the script to the main camera. It does not have to be a camera.
This time, since Text is handled by the script, it is necessary to write “using UnityEngine.UI;”.
In Update, use Input.mousePosition to get the mouse coordinates and assign them to the pos variable.
Finally, the coordinates are written to Text, but since the coordinates are treated as numbers as they are, they are replaced with character data using ToString().

When the game is run, the mouse coordinates can be displayed as shown below.




![[Unity] Removing grass grown on Terrain from scripts](https://kuroko-labo.com/wp/wp-content/uploads/2025/05/grass2.png)
![[Unity] Executing a method at an arbitrary time with Photon’s PUN2](https://kuroko-labo.com/wp/wp-content/themes/kuroko3/images/noimage.png)
![[Unity]I made a field with Gaia Pro 2023.](https://kuroko-labo.com/wp/wp-content/uploads/2025/01/image06.png)
![[Unity]I bought an OLD TV Filter.](https://kuroko-labo.com/wp/wp-content/uploads/2019/11/image05.png)
![[Unity]Try to create a circle gauge that advances when the mouse is clicked.](https://kuroko-labo.com/wp/wp-content/uploads/2019/07/circle.fw_.png)
![[Unity]Use localPosition to create a conveyor belt-like](https://kuroko-labo.com/wp/wp-content/uploads/2019/06/image01-1.png)