Unity3D获取当前键盘按键

获取当前键盘按键,代码如下:

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());
            }
        }
    }
}

 

posted on 2015-11-10 16:57  JMcc  阅读(5538)  评论(0)    收藏  举报

导航