# Screen.CursorLock problems

**URL:** https://discussions.unity.com/t/screen-cursorlock-problems/161261
**Category:** Questions & Answers
**Created:** [March 18, 2016, 10:57pm UTC](https://discussions.unity.com/t/screen-cursorlock-problems/161261 "2016-03-18T22:57:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MechanicalGaming](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@MechanicalGaming](https://discussions.unity.com/u/MechanicalGaming)
#### Post date: [March 18, 2016, 10:57pm UTC](https://discussions.unity.com/t/screen-cursorlock-problems/161261/1 "2016-03-18T22:57:46Z")

</div>

Hey everyone!

I’m having a problem with hiding the cursor and locking it in the middle of the screen. It works at first but when I press esc it comes out of it and won’t go back in.

Here’s the code I am using to try and make this work :

```
void Update()
    {
        //Cursor Lock/Unlock//////////////////////////////////////////////////////////////////////////
        if (Input.GetKeyDown(KeyCode.Escape) && cursorUnlocked == false)
        {
            cursorUnlocked = true;

            Screen.showCursor = true;
            Screen.lockCursor = false;
        }

        if (Input.GetKeyDown(KeyCode.Escape) && cursorUnlocked == true)
        {
            cursorUnlocked = false;

            Screen.showCursor = false;
            Screen.lockCursor = true;
        }
        /////////////////////////////////////////////////////////////////////////////////////////////
    }

```

Thanks for your help guys!

---

<div class="post-metadata">

### Author: ![kevinrocks\_786](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@kevinrocks\_786](https://discussions.unity.com/u/kevinrocks_786)
#### Post date: [March 19, 2016, 12:37am UTC](https://discussions.unity.com/t/screen-cursorlock-problems/161261/3 "2016-03-19T00:37:49Z")

</div>

Im pretty sure that Screen.lock or Screen.showCursor has been removed since Unity 5.0. However, What I use is this: [Unity - Scripting API: Cursor](http://docs.unity3d.com/ScriptReference/Cursor.html)

So if you want to make the cursor visible/invisible, you can simply do:

```
Cursor.visible = true; // Or false

```

And to lock the cursor:

```
Cursor.lockState = CursorLockMode.Locked;

```

And to unlock it:

```
Cursor.lockState = CursorLockMode.None;

```

And take a look at Unity’s Screen class. Notice how there are not cursor variables:

> **[Unity - Scripting API: Screen](https://docs.unity3d.com/ScriptReference/Screen.html)**

---

<div class="post-metadata">

### Author: ![Stabbarey](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/stabbarey/32/982003_2.png) [@Stabbarey](https://discussions.unity.com/u/Stabbarey)
#### Post date: [March 19, 2016, 1:28am UTC](https://discussions.unity.com/t/screen-cursorlock-problems/161261/2 "2016-03-19T01:28:31Z")

</div>

Cursor.lockState = CursorLockMode.Locked;  
Cursor.visible = false;

this is the correct code.
