【Unity】Unity按任意键获取 按键名字

    xiaoxiao2021-04-12  29

    using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class Test : MonoBehaviour { public KeyCode getKeyDownCode() { if (Input.anyKeyDown) { foreach (KeyCode keyCode in Enum.GetValues(typeof(KeyCode))) { if (Input.GetKeyDown(keyCode)) { Debug.Log(keyCode.ToString()); return keyCode; } } } return KeyCode.None; } void Update() { getKeyDownCode(); } }

    就用一个方法

    void OnGUI() { if (Input.anyKeyDown) { Debug.Log(Event.current.keyCode); } }
    转载请注明原文地址: https://ju.6miu.com/read-667648.html

    最新回复(0)