在支持 HTML5 游戏手柄 API 的浏览器上,WebGL 支持游戏手柄和游戏杆(使用 Input 类)。请查看浏览器兼容性表以了解具体是哪些浏览器。
请注意,一旦用户在内容处于焦点状态时与设备进行交互,浏览器可能只允许访问可用的输入设备。这是一种防止将连接的设备用于浏览器指纹识别的安全措施。因此,在检查 Input.GetJoystickNames() 以查找连接的设备之前,务必指示用户点击其设备上的按钮。
虽然 Unity WebGL 尚未正式支持移动设备,但 Input.touches 和相关 API 已在具有触控支持的浏览器和设备上实现,并且还实现了 Input.acceleration。
默认情况下,无论 WebGL 画布是否具有焦点,Unity WebGL 都会处理发送到页面的所有键盘输入。这样做是为了让用户能够立即开始玩基于键盘的游戏,而无需先点击画布进行聚焦。但是,如果页面上有其他 HTML 元素应该接收键盘输入(例如文本字段),这会导致问题,因为 Unity 会在页面的其余部分获取输入事件之前占用输入事件。如果需要让其他 HTML 元素接收键盘输入,可使用 WebGLInput.captureAllKeyboardInput 属性更改此行为。
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.