unity 获取输入按键名称并响应按键消息。
KeyCode currentKey;
void Start () {
currentKey = KeyCode.Space;
}
private void OnGUI()
{
if (Input.anyKeyDown)
{
Event e = Event.current;
if (e.isKey)
{
currentKey = e.keyCode;
//此处不加以判断,会响应两次按键消息
if (currentKey.ToString().CompareTo("Return") == 0)
{
Debug.Log(22222222222);
}
}
}
}