unity 获取当前键盘按键

来源:互联网 发布:mysql数据库视频教程 编辑:程序博客网 时间:2024/05/22 17:15
using UnityEngine;using System.Collections;public delegate void OnTapKey(KeyCode kc);public class InputKeyEvent : MonoBehaviour {public OnTapKey onTapKey;// Use this for initializationvoid Start () {onTapKey += OnGetKeyDown;}void OnGUI(){if (Input.anyKeyDown){Event e = Event.current;if (e != null && e.isKey && e.keyCode != KeyCode.None){//KeyCode currentKey = e.keyCode;//Debug.Log("Current Key is : " + currentKey.ToString());if(onTapKey != null)onTapKey(e.keyCode);}}}void OnGetKeyDown(KeyCode kc){Debug.Log("Current Key is : " + kc);}}


Event 目前支持在OnGUI中实现。



0 0