Unity Web supports Input and InputSystem for gamepads and joysticks for browsers that support the HTML5 Gamepad API.
Some browsers allow access to input devices only after the end user interacts with the device while the application is in focus. This type of security measure prevents the end user from using connected devices for browser fingerprinting purposes. Therefore, your application should instruct the user to press a button on their gamepad/joystick before you call Input.GetJoystickNames() to check for connected devices.
The Web game controller mapping for the old input system aligns with the W3 spec, where the button mapping layout is laid out as follows:
Buttons | 描述 |
---|---|
buttons[0] | Bottom button in right cluster = CROSS (X) |
buttons[1] | Right button in right cluster = CIRCLE |
buttons[2] | Left button in right cluster = SQUARE |
buttons[3] | Top button in right cluster = TRIANGLE |
Note: As Web follows the W3 spec, it might not be consistent with other platforms, and requires unique handling if you’re targeting multiple platforms simultaneously, such as Windows and Web.
Unity Web doesn’t officially support mobile devices (see Web browser compatibility) yet, but it does implement Input.touches and other related APIs in browsers and devices with touch support. By default, mobile devices display a soft keyboard on the touch screen for entering text into UI input fields. To disable this behavior, use the WebGLInput.mobileKeyboardSupport property.
By default, Unity Web processes all keyboard input the web page receives, regardless of whether the Web canvas has focus or not. This allows the end user use a keyboard-based application without the need to click on the Web canvas.
The following notes apply to specific keyboard inputs as described below:
Keyboard input behavior | 描述 |
---|---|
HTML elements (such as text fields) | Typically, introducing HTML elements (such as text fields) can cause errors if included in the web page that’s meant to receive keyboard inputs. Unity consumes the input events before the rest of the page can receive them. To make HTML elements receive a keyboard input, set WebGLInput.captureAllKeyboardInput to false . This way, the application receives input only if the Web canvas has focus. |
Esc key | Because the Esc key is protected in the web environment, some browsers like Safari block the ability to use it to switch to full-screen mode and others like Google Chrome behave unpredictably. When the browser is in full-screen mode, the Esc key is reserved for the action of exiting the full-screen mode. Depending on your browser type, clicking the Esc key might not always trigger the event to forward from the browser to the application. |
HideMobileInput |
The HideMobileInput option in TextMeshPro (also known as TMP) input fields has no effect on the Web platform. This is because a text input field is required to trigger the virtual keyboard in browsers. The Web platform instantiates a text input field to trigger the virtual keyboard when the Unity player is expecting text entry, which appears above the virtual keyboard much like other platforms. Because the virtual keyboard relies on the mobile text input field, it can’t appear hidden on the web platform. |
Unity Web doesn’t officially support mobile devices (see Web browser compatibility), but for browsers and mobile devices with touch support, Unity Web includes support for the following sensors:
Important: Browsers allow sensor input only in secure contexts, which means, you must serve the page over HTTPS. The single exception is http://localhost
, which you can use during development.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.