Version: 2021.1
public static bool GetKey (string name);

描述

在用户按下 name 标识的键时返回 true。

GetKey 将报告指定键的状态。 可以使用该函数确认用于自动开火的键。有关键标识符的列表, 请参阅输入管理器。 处理输入时,建议改用 Input.GetAxis 和 Input.GetButton,因为 这允许最终用户对键进行配置。

iOS、tvOS:由于平台限制,键盘事件的.GetKeyUp 事件延迟大约半秒,请参阅生成的 Xcode 项目中的 UnityView+Keyboard.mm 了解更多信息。

using UnityEngine;
using System.Collections;

public class ExampleClass : 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"); } } }

public static bool GetKey (KeyCode key);

描述

在用户按下 key KeyCode 枚举参数标识的键时返回 true。

using UnityEngine;
using System.Collections;

public class ExampleClass : 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"); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961