回车键。
用于确认一行文本的键。macOS 将其称为 Return
。PC 将其称为 Enter
。没有 KeyCode.Enter
。在 PC 上使用 Return。某些笔记本电脑的 Return
或 Enter
键上没有名称。
// KeyCode.Return example. // // Attach this to a GameObject. // This script tells when the Return key is pressed down and when it is released.
using UnityEngine;
public class Example : MonoBehaviour { void Update() { //Detect when the Return key is pressed down if (Input.GetKeyDown(KeyCode.Return)) { Debug.Log("Return key was pressed."); }
//Detect when the Return key has been released if (Input.GetKeyUp(KeyCode.Return)) { Debug.Log("Return key was released."); } } }