一般情况下都是用update()函数进行输入检测

但是update毕竟是在每次渲染新的一帧才会调用,如果害怕漏了检测可以使用一下的方式进行输入的判定

using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
 void OnGUI()
 { 
      if (Event.current.Equals(Event.KeyboardEvent("[enter]"))) 
      {
          print("你按下了“Enter”键!");
      } 
      if (Event.current.Equals(Event.KeyboardEvent("return"))) 
      {
           print("你按下了“Return”键!");
      }
        //Ctrl + Alt + X 执行截屏  
        if(Event.current.Equals(Event.KeyboardEvent("^&X")))  
        {  
            screenshot.enabled = true;  
        }  
    }
}

  

posted on 2021-10-08 17:53  白叡  阅读(863)  评论(0)    收藏  举报