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

描述

Returns true while the user holds down the key identified by name. Think auto fire.

有关键标识符的列表,请参阅输入管理器。 处理输入时,建议改用 Input.GetAxis 和 Input.GetButton,因为 这允许最终用户对键进行配置。

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"); } }