Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to Resolve Mouse Lock Issue

Discussion in 'Editor & General Support' started by Xander-Davis, Mar 15, 2016.

  1. Xander-Davis

    Xander-Davis

    Joined:
    Apr 23, 2011
    Posts:
    441
    It seems the mouse doesn't lock to the center of the screen when running the project. I had a script to fix this last year but now that no longer works.

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. public var cursorTexture: Texture2D;
    4. public var cursorMode: CursorMode = CursorMode.ForceSoftware;
    5. public var hotSpot: Vector2 = Vector2.zero;
    6.  
    7. function Start () {
    8. //    ResetAspect();
    9.     CustomCursor();
    10. }
    11.  
    12. function Update () {
    13.     Cursor.visible = false;
    14. }
    15.  
    16. function ResetAspect () {
    17.  
    18. }
    19.  
    20. function CustomCursor() {
    21.     Cursor.visible = false;
    22.     Cursor.lockState = CursorLockMode.Locked;
    23.     Cursor.SetCursor(cursorTexture, hotSpot, cursorMode);
    24.     Cursor.visible = false;
    25. }
    Any advice on how to resolve this?