Class WebGLPointerLockGuard
Installs the browser-side pointer-lock guard (PointerLockGuard.jslib) before the first scene loads.
public static class WebGLPointerLockGuard
- Inheritance
-
WebGLPointerLockGuard
- Inherited Members
Remarks
The game locks the cursor on its own (MouseMode), not only from a click, and a browser refuses a pointer lock that is not requested inside a user gesture. Unity's runtime ignored the refusal: the console showed "Uncaught (in promise) NotAllowedError: A user gesture is required to request Pointer Lock" and the cursor stayed free. The guard handles the refusal and takes the lock on the player's next mouse press, unless the game has freed the cursor by then. Nothing outside a WebGL player.
The guard also reports a lock the browser ended — Escape, which no page can cancel, or a switch of tab or window. Unity's runtime says nothing about it, so the game kept believing the cursor was captured while the player was looking at a free one. ConsumeBrowserRelease() hands that to the world's input controller, which frees the cursor to match.
Methods
ConsumeBrowserRelease()
True once after the browser ended a pointer lock the game still wanted; clears itself.
public static bool ConsumeBrowserRelease()
Returns
Remarks
Polled from the player loop rather than acted on in the callback: the callback runs from a browser event, outside Unity's frame, and freeing the cursor raises OnToggleMouseMode, whose UI subscribers belong inside it. Always false outside a WebGL player.