Search Unity

Hide and lock cursor?

Discussion in 'Getting Started' started by Spiele4F, Apr 4, 2015.

  1. Spiele4F

    Spiele4F

    Joined:
    Jun 10, 2014
    Posts:
    2
    I'm really newbie for all things (including programming), and i need a script that starts with the mouse invisible and locked and when i press esc it's turn visible and unlocks.

    Probably it's not that difficult, but i'm having problems with that xD.

    -Sorry for the bad 30% Google Translated english and the newbie question :p
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,192
    This will lock it to the center of the screen and hide it.

    Code (csharp):
    1. Cursor.lockState = CursorLockMode.Locked;
    2. Cursor.visible = false;
    Then to unlock and make it visible.

    Code (csharp):
    1. Cursor.lockState = CursorLockMode.None;
    2. Cursor.visible = true;
     
    Spiele4F likes this.
  3. Spiele4F

    Spiele4F

    Joined:
    Jun 10, 2014
    Posts:
    2
    Thanks :D