public static bool GetKeyDown (string name);

Description

在用户开始按下 name 标识的键的帧期间返回 true。

您需要从 Update 函数调用该函数(因为每帧都会重置状态)。 在用户释放键并再次按键之前,它不会返回 true。

For the list of key identifiers see Conventional Game Input. When dealing with input it is recommended to use Input.GetAxis and Input.GetButton instead since it allows end-users to configure the keys.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Update() { if (Input.GetKeyDown("space")) { print("space key was pressed"); } } }

public static bool GetKeyDown (KeyCode key);

Description

在用户开始按下 key KeyCode 枚举参数标识的键的帧期间返回 true。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.Space)) { print("space key was pressed"); } } }