0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Unity] 旧Inputと new Input Systemの切り分け

Posted at

InputSystemが導入されて何年も経ち、AIでもようやくちらほら提案されるようになったように感じます。

これまではPlayer > Active Input Handring > Both にしておくのが定番の処理でしたが、
image.png

今後は旧InputをInputSystemに置き換えていくのが良いかもしれません。

一般的にはInputSystemはUpdate()内で処理をするのではなく、イベントから呼び出される形で用いることが多いのですが、Update()内で直接Keyboard.currentを調べることで旧Inputから置き換えることも可能です。

#if NEW_INPUT_SYSTEM_INSTALLED
using UnityEngine.InputSystem;
#endif

  :

#if ENABLE_INPUT_SYSTEM && NEW_INPUT_SYSTEM_INSTALLED
            // New input system backends are enabled.
            if (Keyboard.current.aKey.isPressed)
            {
            }
            else if (Keyboard.current.dKey.isPressed)
            {
            }
            :
#else
            // Old input backends are enabled.
            if (Input.GetKey(KeyCode.A))
            {
            }
            else if(Input.GetKey(KeyCode.D))
            {
            }
            :
#endif

両方のInputをソースコード内で共存させたい場合は
ENABLE_INPUT_SYSTEMNEW_INPUT_SYSTEM_INSTALLED を使って切り分けをすることもできます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?