- Home /
prevent mouse from leaving screen
My camera fallows my mouse but my mouse keeps leaving the screen. How would prevent my mouse from leaving the screen, so if you scroll all the way to the right , you can keep scrolling. I only know java script
I don't believe this is possible in Unity. If it is I'll be delighted to be proven wrong.
Answer by CodeMasterMike · Jan 02, 2013 at 06:40 AM
I don't think its possible to do something like that, so you need to re-think your design.
For example, you can use the Lock mouse cursor function, (LockCursor documentation) to have the mouse cursor to be in the center all the time, and use GetAxis input to get when the mouse moves, and use its data to move the camera (pseudo code!):
var xAxis = Input.GetAxis ("Mouse X");
var yAxis = Input.GetAxis ("Mouse Y");
YourCamera.Transform.Translate(xAxis, yAxis , 0);
Good luck!
Worked perfictly, but is there any way to still lock the mouse but not hide it
You can use your own pointer texture and set it at the mouse position for instance.
Or you can try the showCursor variable. I don't know if you can use that one and the LockCursor at the same time, but maybe worh a try:
Screen.showCursor = true;
http://docs.unity3d.com/Documentation/ScriptReference/Screen-showCursor.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613090238im_/https://answers.unity.com/themes/thub/images/avi.jpg)