Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How do I lock the mouse for Multi Display

Discussion in 'Scripting' started by S-P-A-R-K, Sep 15, 2023.

  1. S-P-A-R-K

    S-P-A-R-K

    Joined:
    Nov 13, 2022
    Posts:
    2
    I am making my character's camera move when the mouse moves left or right, (1st person) but I need to lock the mouse

    I have the mouse locked and Invisible but when it moves out of the radius of my first monitor, it goes to the second or third


    Code:

    void Update()
    {
    if(Input.GetMouseButtonDown(0))
    {
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    }

    if (Input.GetKeyDown(escapeKey))
    {
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
    }
    }


    how can I get it so that it doesn't go to the second or third monitor unless I click Escape?

    (also I am new to Unity)
     
  2. wideeyenow_unity

    wideeyenow_unity

    Joined:
    Oct 7, 2020
    Posts:
    728
    I'm not sure you can, unless you control the bounds of the mouse values itself. But regardless from an indie game to full AAA title, if I move my mouse over to a "multiple" display setup, my mouse always goes into the next display.

    I did to a point, just set settings in windows itself to turn off another display, if I only wanted to focus one(gaming), and that worked. So that leads me to believe that's a microsoft thing, not anything to do with unity itself.

    Not sure though, haven't explored that further, myself..
     
  3. S-P-A-R-K

    S-P-A-R-K

    Joined:
    Nov 13, 2022
    Posts:
    2
    when im playing any other game for me its fine, but just not in unity