Search Unity

Cursor.lockState does not behave properly

Discussion in 'Scripting' started by LaneFox, Jun 30, 2015.

  1. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,525
    Code (csharp):
    1.  
    2.     void Start ()
    3.     {
    4.        Cursor.lockState = CursorLockMode.Locked;
    5.     }
    6.  
    Editor: This will lock the cursor, but it sticks it randomly in one of a few different positions instead of the center of the screen. I've seen it in three different places when the code tells it Vector2.zero after I just ran it several times in a row with no changes.
    Build: Didn't test.

    Code (csharp):
    1.  
    2.     void Start()
    3.     {
    4.         Cursor.lockState = CursorLockMode.Confined;
    5.     }
    6.  
    Editor: Doesn't confine to the Game Window.
    Build: Didn't test.

    Anyone else experiencing this? I've found quite a few people are having problems with it while others are using it just fine, and I'm curious if this is a known issue or not. Is it a hardware problem?

    Cursor.SetCursor(...) seems to work fine for me with texture and hotspot, but the lockStates do not. Mixed results with visibility.
     
  2. ShivaFooL

    ShivaFooL

    Joined:
    Jul 3, 2010
    Posts:
    16
    I'm having problems with it too. Besides discussions in the forums, it's also been addressed in answers.unity3d.com. Someone mentioned they had filed a bug report, and I don't know if this is resolved in the latest update. It certainly hasn't worked as advertised for me.