docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Query and control mouse devices in code

    You can use the Mouse class to control how mouse devices work with your application.

    Query the last mouse

    To query the last used or last added mouse, use Mouse.current:

    
       var mouse = Mouse.current;
    
    

    Move the mouse cursor

    On desktop platforms (Windows, macOS, Linux, and Universal Windows Platform), you can move the mouse cursor with code with the WarpCursorPosition method.

    WarpCursorPosition moves the system's actual mouse cursor, not just Unity's internally stored mouse position. This means that the user sees the cursor jumping to a different position, which is generally considered to be bad practice. It's best practice to only do this if the cursor is hidden. For information on how to hide a cursor, refer to the Cursor API documentation.

    To move the cursor to a different position, use Mouse.WarpCursorPosition. The coordinates are expressed as Unity screen coordinates, just like Mouse.position.

    
       Mouse.current.WarpCursorPosition(new Vector2(123, 234));
    
    
    Note

    If the cursor is locked, warping the mouse position is only temporary and Unity resets the cursor to the center of the window every frame.

    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)