Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Input.GetJoystickNames 获取控制杆名称列表
# [Input](Input.html).GetJoystickNames 获取控制杆名称列表 static function *GetJoystickNames* () : string[] *Description* 描述 Returns an array of stings describing the connected joysticks. 返回一个用来描述已连接的控制杆的字符串集合。 This can be useful in user input configuration screens - this way, instead of showing labels like "Joystick 1", you can show more meaningful names like "Logitech WingMan". To read values from different joysticks, you need to assign respective axes for the number of joysticks you want to support in the input manager. 它可以用在用户输入设置界面 --这样,你就可以把显示的标签"Joystick 1"换成意义更明确的名字像"Logitech WingMan",读取不同控制器的值,你需要分别为各个控制器的数字指定指方向轴如果你想将其使用在输入设置中。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Update() { int i = 0; while (i < 4) { if (Mathf.Abs(Input.GetAxis("Joy" + i + "X")) > 0.2F || Mathf.Abs(Input.GetAxis("Joy" + i + "Y")) > 0.2F) Debug.Log(Input.GetJoystickNames()[i] + " is moved"); i++; } } } ``` ``` // Prints a joystick name if movement is detected. //如果检测到移动就输出一个控制杆名称 function Update () { // requires you to set up axes "Joy0X" - "Joy3X" and "Joy0Y" - "Joy3Y" in the Input Manger //你需要在输入管理器中设置方向轴"Joy0X" - "Joy3X" 和 "Joy0Y" - "Joy3Y" for (var i : int = 0; i < 4; i++) { if (Mathf.Abs(Input.GetAxis("Joy"+i+"X")) > 0.2 || Mathf.Abs(Input.GetAxis("Joy"+i+"Y")) > 0.2) Debug.Log (Input.GetJoystickNames()[i]+" is moved"); } } ```
da
2022年5月23日 14:00
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码