Search Unity

CursorLockMode

Discussion in 'Scripting' started by Black_Raptor, May 26, 2020.

  1. Black_Raptor

    Black_Raptor

    Joined:
    Nov 3, 2014
    Posts:
    181
    hi !

    I going to turn crazy, after many day of research, i can't figure out of my problem, i use CursorLockMode to lock my cursor in the center of my screen, but when i do that i can't use UI in global space, i have to unlock my cursor to press any button ...

    What i want is to have my cursor invisible and center to my screen and still can press button ... I tryed to perform raycast from the center of my screen with camera.ScreenPointToRay(Input.mousePosition) but that not work ...

    Please help me
     
  2. MA_Alsyakel

    MA_Alsyakel

    Joined:
    Feb 28, 2020
    Posts:
    2
    Use this:
    Code (CSharp):
    1. Cursor. Lockstate= CursorLockMode. Locked
    2.  
    3. if (Input. GetKey("escape" ))
    4. {
    5.      Cursor.lockState = Cursor.LockState.Unlocked;
    6. }
    That means if you press the Esc button it will unlock the cursor