一般情況下都是用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;
}
}
}
