using UnityEngine; namespace UnityHFSM.Samples.Sample3d { [RequireComponent(typeof(Rigidbody))] public class PlayerController : MonoBehaviour { public static PlayerController Instance { get; private set; } [SerializeField] private float speed = 2; private Rigidbody rb; private void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); } else { DontDestroyOnLoad(gameObject); Instance = this; } } private void Start() { rb = GetComponent(); } private void FixedUpdate() { Vector3 playerInput = new Vector3( Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical") ); rb.velocity = playerInput * speed; } private void OnDestroy() { if (Instance == this) { Instance = null; } } } }