- Home /
Controlling Players Mouse
Is it even possible to code a script that moves the mouse cursor by its own? And if so I would very much like to see how it can be done :)
Answer by SirPepato · Jul 20, 2018 at 12:59 AM
I believe the mouse position cannot be changed and is basically read-only, so I would suggest hiding the mouse using Cursor.visible = false;
and creating a fake mouse cursor that follows the real mouse and interacts with screen elements and whatever. You can then move the fake mouse cursor instead, and the player will be none the wiser. The game I'm currently creating also uses a fake mouse cursor. Here is the code I use to fix it's position to the mouse position:
void Update () {
Vector3 mouse = Input.mousePosition;
mouse.z = 1f;
this.transform.position = Camera.main.ScreenToWorldPoint(mouse);
}
Answer by Cynikal · Jul 20, 2018 at 01:05 AM
You can move the mouse, but it requires some trickery and the use of native extensions of the OS.
Here is an example:
https://answers.unity.com/questions/564664/how-i-can-move-mouse-cursor-without-mouse-but-with.html