Version: 2021.2

Input.anyKeyDown

切换到手册
public static bool anyKeyDown ;

描述

在用户按任意键或鼠标按钮后的第一帧返回 true。(只读)

您应该从 Update 函数轮询该变量(因为每帧都会重置状态)。 在用户释放所有键/按钮并再次按任意键/按钮前,它不会返回 true。 不检测触摸操作。对于触摸操作,请使用 Input.touchCount

using UnityEngine;

public class Example : MonoBehaviour { // Detects if any key has been pressed down.

void Update() { if (Input.anyKeyDown) { Debug.Log("A key or mouse click has been detected"); } } }