テストキャラを作成して動かす



InputManager
using UnityEngine;
public class InputManager : MonoBehaviour
{
public static InputSystem_Actions isa { get; set; }
// シングルトン
void Awake()
{
if (isa == null)
{
isa = new InputSystem_Actions();
isa.Enable();
// シーンを遷移しても破棄しない
DontDestroyOnLoad(this.gameObject);
}
else
{
Destroy(this.gameObject);
}
}
// オブジェクトが破棄される直前に実行される(ゲーム終了時)
void OnDestroy()
{
if (isa != null)
{
// インスタンスしたInputManagerクラスを破棄する。
isa.Disable();
isa = null;
}
}
}




TestMove
using UnityEngine;
public class TestMove : MonoBehaviour
{
private float moveSpeed = 5f;
private float turnSpeed = 50f;
void Update()
{
Vector2 movement2 = InputManager.isa.Player.Move.ReadValue<Vector2>();
transform.Translate(Vector3.forward * movement2.y * Time.deltaTime * moveSpeed);
transform.Rotate(Vector3.up * movement2.x * Time.deltaTime * turnSpeed);
}
}

【Unity6版】BattleOnline(全38回)
他のコースを見る


InputManager
using UnityEngine;
public class InputManager : MonoBehaviour
{
public static InputSystem_Actions isa { get; set; }
// シングルトン
void Awake()
{
if (isa == null)
{
isa = new InputSystem_Actions();
isa.Enable();
// シーンを遷移しても破棄しない
DontDestroyOnLoad(this.gameObject);
}
else
{
Destroy(this.gameObject);
}
}
// オブジェクトが破棄される直前に実行される(ゲーム終了時)
void OnDestroy()
{
if (isa != null)
{
// インスタンスしたInputManagerクラスを破棄する。
isa.Disable();
isa = null;
}
}
}




TestMove
using UnityEngine;
public class TestMove : MonoBehaviour
{
private float moveSpeed = 5f;
private float turnSpeed = 50f;
void Update()
{
Vector2 movement2 = InputManager.isa.Player.Move.ReadValue<Vector2>();
transform.Translate(Vector3.forward * movement2.y * Time.deltaTime * moveSpeed);
transform.Rotate(Vector3.up * movement2.x * Time.deltaTime * turnSpeed);
}
}

テストキャラを作成して動かす