How to always have the mouse curser in the center of your game ?

Hey guys im making a first person shooter and i have one problem with my view. At first when i start my game, im good untill i start moving alot and eventually my mouse is no longer in the center of my screen like how i wanted to be some times is on the side or bottom.

I want it so that i have a target in the middle of my screen at all times .

I use the MouseLook Script that comes whith the island demo. Any help would be sweet for i need to fix this to keep advancing.Ty in advance!! =)

Try having a look at the First Person Shooter tutorial /demo : http://unity3d.com/support/resources/tutorials/fpstutorial.html

You can use Screen.lockCursor: file:///Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/Screen-lockCursor.html

Locking the cursor

Note: This has a side effect of making the cursor invisible.

Use the following code to lock the cursor to the center of the screen.

Cursor.lockState = CursorLockMode.Locked

This can be ideal when using mouse input for pan/tilt or pitch/yaw type controls, i.e. camera pan/title or spacecraft movements


More info, including different lockstates can be found here:

Unity - Scripting API: Cursor