獲取當前鍵盤按鍵,代碼如下:
using UnityEngine;
using System.Collections;
public class GetCurrentKey : MonoBehaviour {
KeyCode currentKey;
void Start ()
{
currentKey = KeyCode.Space;
}
void OnGUI()
{
if (Input.anyKeyDown)
{
Event e = Event.current;
if (e.isKey)
{
currentKey = e.keyCode;
Debug.Log("Current Key is : " + currentKey.ToString());
}
}
}
}