はじめに
「InputBinder」を Unity プロジェクトに導入することで
入力を簡単にバインディングできるようになります
使い方
入力をバインディングしたいオブジェクトに
「Input Binder」をアタッチします
そして、下記のようなスクリプトを作成します
using RyanNielson.InputBinder; using UnityEngine; public class Example : MonoBehaviour { public InputBinder m_binder; private void Start() { m_binder = GetComponent<InputBinder>(); m_binder.BindAxis( "Horizontal", Horizontal ); m_binder.BindAxis( "Vertical" , Vertical ); m_binder.BindButton( "Jump", InputEvent.Pressed , JumpPressed ); m_binder.BindButton( "Jump", InputEvent.Released, JumpReleased ); m_binder.BindButton( "Jump", InputEvent.Held , JumpHeld ); } private void Horizontal( float value ) { Debug.Log( "Horizontal " + value ); } private void Vertical( float value ) { Debug.Log( "Vertical " + value ); } private void JumpPressed() { Debug.Log( "JumpPressed" ); } private void JumpReleased() { Debug.Log( "JumpReleased" ); } private void JumpHeld() { Debug.Log( "JumpHeld" ); } }
あとは、このスクリプトをゲームオブジェクトにアタッチして
Inspector で「Input Binder」を設定すると、
矢印キーやスペースキーを押した時にイベントが呼び出されることが確認できます
Inspector で各種イベントを設定することも可能です