0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Unity Input System

Last updated at Posted at 2021-01-18

環境

Unity2019.4.16
OS : windows10 pro
IDE : VS2019 free

概要

InputSystemを使用するにはUnity 2019.1以降+および.NET 4ランタイムが必要

参考

https://forpro.unity3d.jp/unity_pro_tips/2021/05/20/1957/
http://tsubakit1.hateblo.jp/entry/2019/01/09/001510

Unityの新しい入力システムInputSystemを使ってみる

image.png

メモ1

・Package ManagerでInputSystemをインストール
・Net4.0にする
・上記の[Player]-[Active Input Handling]をBothまたはInput System Package(New)にする
・Createボタンを押す

Unity再起動します。次の画面になります。

image.png

対応したいキーボード、マウス、VR(Oculus)などのデバイスを追加する。
image.png

アクション設定ファイル

image.png

マウスの認識

Unity2020.2.0f1 だとマウス認識されない、Mouse.current==NULLになる。つかえない?

image.png

    if (Mouse.current!=null){
            if( Mouse.current.leftButton.wasPressedThisFrame){
                Debug.Log("マウスの左ボタンが押された");

            }
        }

コード

OnArrow,OnFireに着目。

image.png

public class UnityEventScript : MonoBehaviour
{
    public void OnFire(InputAction.CallbackContext context)
    {
        Debug.Log(context);
    }

    public void OnMove(InputAction.CallbackContext context)
    {
        var value = context.ReadValue<Vector2>();
        Debug.Log(value);
    }
}
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?