x


Mouse exclusive to my game

How do I make the mouse exclusive to the game? I am new to all this and still in school, but I cannot figure out how to make it so when you play the game the cursor goes away. We use dual monitors here and if I keep trying to look right the mouse goes off the screen onto the other monitor. It would be much appreciated if someone could help out.

Thank you.

more ▼

asked Sep 24 '10 at 03:27 AM

James 6 gravatar image

James 6
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Take a look at Screen.lockCursor.

Updated to highlight web-player-specific behaviour:

In the web player the cursor may only only be locked after the user has clicked on the content and the user has not left the content view with the cursor. After the user presses escape or switches to another application the cursor will be automatically unlocked. The cursor lock will also be lost when exiting full screen mode. You can query if the cursor is currently locked by checking the lockCursor state. To provide a good user experience it is recommended to only lock the cursor as a result of pressing a button. Also you should check if the cursor got unlocked, in order to e.g. pause the game or bring up a game menu. In the Web Player and Editor the cursor will automatically be unlocked when you press escape. In the Standalone Player you have full control over mouse locking thus it won't automatically lose mouse lock unless you switch applications.

more ▼

answered Sep 24 '10 at 03:35 AM

Marowi gravatar image

Marowi
4.9k 4 14 53

Ok I added that in, but it does not lock it. I build and run the game and it opens in the unity web player but the cursor is still there and as I look left or right the cursor still moves off of the program.

Any ideas for that or maybe I set up the script wrong or put it in the wrong place. Any ideas? Thank you.

Sep 24 '10 at 04:01 AM James 6

What exactly does that mean? My understanding is that once you click in the window it will lock it in right? When I click in the screen my weapon fires but the cursor does no lock in. I'm still a little confused. Sorry for the inconvenience.

Sep 24 '10 at 05:00 AM James 6

You need to lock it once the web player has focus, and every time it regains focus. I didn't include that in my initial answer because your question didn't mention that it was for the web player - sorry!

Sep 24 '10 at 05:26 AM Marowi

Alright, I will give it a shot. I will let you know how it went on Teusday. Thank you for your help.

Sep 25 '10 at 03:40 AM James 6
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x983
x21

asked: Sep 24 '10 at 03:27 AM

Seen: 1343 times

Last Updated: Sep 24 '10 at 03:42 AM