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 Forcing Mouse Position In WebGL

Discussion in 'WebGL' started by JonathanPersson, Feb 14, 2022.

  1. JonathanPersson

    JonathanPersson

    Joined:
    May 10, 2020
    Posts:
    1
    Hello!

    I'm using the following code snippet to force the mouse position to stay inside an area. It works great for my specific case. Sadly this solution does not seem to work in WebGL (using itch.io).

    Are there any known workarounds, or other methods to force the mouse position within WebGL?

    Code (CSharp):
    1. Mouse.current.WarpCursorPosition(clampedPos);
    2. InputState.Change(Mouse.current.position, clampedPos);
     
  2. TomTrottel

    TomTrottel

    Joined:
    Aug 16, 2014
    Posts:
    18
    I need to be able to set the mouse position by code in WebGL, too.

    I did not find a way yet. It works fine with Windows Builds.

    From the docs : "On desktop platforms (Windows, Mac, Linux, and UWP), you can move the mouse cursor via code."

    Implying that it is not possible in WebGL via Code.

    If I can not find a way, I can not combine the UIToolkit UIElements with my RTS Map.

    (I meant to have seen somewhere that people communicate via JavaScript with the webpage and set the cursor position there ... but I dismissed it as too far fetched.)