Unity InputSystem 基础使用之键盘交互

获取键盘

Keyboard keyboard = Keyboard.current 

键盘交互

keyboard[Key.Space].isPressed  按下空格键持续
keyboard[Key.Space].wasPressedThisFrame  按下空格键
keyboard[Key.Space].wasReleasedThisFrame 抬起空格键

获取键盘字符输入

    Keyboard keyboard;
    private void Awake()
    {
        keyboard = Keyboard.current;
        keyboard.onTextInput += onTextInput; 注册事件
    }
    private void onTextInput(char obj) 打印获取的字符
    {
        Debug.Log("键盘输入" + obj);
    }
    private void OnDestroy()
    {
        keyboard.onTextInput -= onTextInput; 取消注册
    }

你可能感兴趣的:(Unity经验,unity,计算机外设,游戏引擎)