はじめに
作成したInputActionの使用方法がコールバックを登録する使い方しか出てこずif(GetKeyDown~みたいに使用する方法がみつからなかったのでメモ
環境は Unity 2021.3.25f1です
スクリプト作成
actionsから指定したInputActionを取得できるのでそれを判定に使用します
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; public class InputTest : MonoBehaviour { public PlayerInput input; InputAction Test; private void Start() { Test = input.actions["Test"];//InputActionをキャッシュ } void Update() { //Input.GetKeyDown if (Test.WasPressedThisFrame()) { Debug.Log("押した"); } //Input.GeKkey if (Test.IsPressed()) { Debug.Log("長押し"); } //Input.GetKeyUp if (Test.WasReleasedThisFrame()) { Debug.Log("離した"); } } }
ActionMapはこんな感じ
セーブしてから動作確認しましょう
参考 https://docs.unity3d.com/Packages/com.unity.inputsystem@1.2/manual/Migration.html