Cursor Visibility...

I researched before posting this…

So basically I don’t know why, but when I was making/editing my game, suddenly when I play it, the mouse is visible and it’s not locked…

So I researched how to lock my cursor and I tried everything! Like this (I created a JS Script and just tried these little codes)

1st try

function Start ()
Cursor.visible = false;

2nd try

function Start ()
Cursor.lockState = CursorLockMode.Locked

3rd try

function Start ()
Cursor.visible = false;

function Update ()
Cursor.lockState = CursorLockMode.Locked

None of these worked :frowning: can someone help?

Did you actually attach this script to an object in your scene?
Try adding a Debug.Log to the Start so you can see if it is actually getting called.

Just to make sure you used this code right?

function Start()
{
    Cursor.visible = false;
    Debug.Log("Cursor should now be hidden!");
}

(Insert obligatory use C# because JS/US is being deprecated (Abandoned))

Unfortunately Unity’s documentation neglects the most important part. Unity’s editor is overriding them. They will work just fine from a build, but the editor won’t allow them to function in Edit mode or in Play mode.

2 Likes

So when if I finish the game and export it… the cursor will not be visible? But only in edit or play mode it’s unlocked and visible?

Correct.

Announcement blog post about it just appeared too.

https://blogs.unity3d.com/2017/08/11/unityscripts-long-ride-off-into-the-sunset/

1 Like

You don’t need to finish it - sometimes it’s a good idea to export the standalone player when something is acting up :slight_smile:

2 Likes

So I built my game and my cursor was visible and was not locked…

Then it must be something else that’s changing its state, I’d say.

wait… I still have to make a script for the cursor to be locked and visible right?

E.g:
Function Start ()
Cursor.lockState = CursorLockMode.Locked

If so then I’m dumb.

lol… I hear ya, kindly. I got it a little backwards, too. Yep, gotta lock + hide it then test unlocking/unhiding it . :slight_smile: :slight_smile: