Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Input.GetKey 获取键
# [Input](Input.html).GetKey 获取键 static function *GetKey* (*name* : string) : bool *Description* 描述 Returns true while the user holds down the key identified by name. Think auto fire. 当通过名称指定的按键被用户按住时返回 true。想想自动开火。 For the list of key identifiers see Input Manager. When dealing with input it is recommended to use [Input.GetAxis](Input.GetAxis.html) and [Input.GetButton](file:///E:/Program%20Files/Unity/Editor/Data/Documentation/Documentation/ScriptReference/Input.GetButton.html) instead since it allows end-users to configure the keys. 按键的标识符列表可以在输入管理器中找到,当处理输入时推荐使用 Input.GetAxis 和 Input.GetButton,它们允许最终用户自定义按键。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Update() { if (Input.GetKey("up")) print("up arrow key is held down"); if (Input.GetKey("down")) print("down arrow key is held down"); } } ``` ``` function Update () { if (Input.GetKey ("up")) print ("up arrow key is held down"); if (Input.GetKey ("down")) print ("down arrow key is held down"); } ``` • static function *GetKey* (*key* : [KeyCode](../Enumerations/KeyCode/KeyCode.html)) : bool *Description* 描述 Returns true while the user holds down the key identified by the key [KeyCode](../Enumerations/KeyCode/KeyCode.html) enum parameter. 当通过按键枚举参数指定的按键被用户按住时返回 true。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Update() { if (Input.GetKey(KeyCode.UpArrow)) print("up arrow key is held down"); if (Input.GetKey(KeyCode.DownArrow)) print("down arrow key is held down"); } } ``` ``` function Update () { if (Input.GetKey (KeyCode.UpArrow)) print ("up arrow key is held down"); if (Input.GetKey (KeyCode.DownArrow)) print ("down arrow key is held down"); } ```
da
2022年5月23日 14:00
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码