x


Locking the Cursor at the center.

I've been looking at answers, and I don't understand them. All I want is a script that will lock the cursor at the center of the screen for a stand-alone game. Just one script, NOTHING ELSE.

more ▼

asked Jan 13 '11 at 06:50 AM

Irsan gravatar image

Irsan
65 39 42 50

Except for the simplest of things, it rarely works to simply drop a script into a project and have it do what you want, and your request is non-trivial. You're probably best off studying people's proposed answers to see what might work best in your situation, and perhaps finding a programmer friend you can talk to face to face to explain some of the more intricate details.

Jan 13 '11 at 09:26 AM yoyo
(comments are locked)
10|3000 characters needed characters left

3 answers: sort newest
void Update()
{
if (Input.GetKey(KeyCode.Escape))
    Screen.lockCursor = false;
else
    Screen.lockCursor = true;
}

Press and hold escape to unlock the mouse.

more ▼

answered Jul 18 '12 at 06:33 PM

Nsmurf gravatar image

Nsmurf
38 1 4

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

I've been looking at threads about this problem and haven't found an easy enough answer, so I thought I'd add my two cents:

It's not a perfect solution bot for prototyping purposes I use this:

function Update () {
    Screen.lockCursor = true;
    Screen.lockCursor = false;
}

Screen.lockCursor moves the pointer to the center of the screen, so it does almost exactly what the OP suggested - resets the cursor every frame.

You could also use a MouseMove event for example :)

Not very clean but it does the job, you retain OnMouseDown functionality, the cursor remains visible.

more ▼

answered May 12 '12 at 10:37 AM

Ravenmore gravatar image

Ravenmore
35 1 1

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

Hello.

I needed what you want during a testing proyect. I used "Screen.lockCursor" to block the cursor in the center of screen to simulate the pointer of a gun.

Here you have the API example: ScreenLookCursor

I hope its what you want. See you.

more ▼

answered Jan 13 '11 at 10:53 AM

juan_txo gravatar image

juan_txo
11 1

(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:

x1001
x202
x134
x129

asked: Jan 13 '11 at 06:50 AM

Seen: 6078 times

Last Updated: Jul 18 '12 at 06:33 PM