トマシープが学ぶ

Unity/VR/AR/デザイン好きのミーハー 記事内容は自分用のメモです

新InputSystemでKeyInputはどう書くの?【Unity】

InputManagerとInputSystem

Unity2020.3でいつものようにInput.GetKeyDown(KeyCode.Space)を書いた。

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
           //
        }
    }

実行したらエラー出て、キー操作が反応しない

InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.

InputSystemが新しくなったらしいね・・・

qiita.com

InputManagerが旧。

InputSystemが新

InputSystemを使ったキー入力はどう書けばいいんだろう。

回避

とりあえず回避策として、PlayerSettingsのActive Input HandlingでBothを選んだらどっちも使える

f:id:bibinbaleo:20210624095832p:plain

書き方

こちらの記事を参考にした

gametukurikata.com

 

using UnityEngine.InputSystem;

を書いたうえで

if (Keyboard.current.spaceKey.isPressed)

で反応する!

 

リファレンスはここかな?

docs.unity3d.com