using UnityEngine; public class PlayerController : MonoBehaviour { [SerializeField] private int speed; [SerializeField] private Animator anim; [SerializeField] private SpriteRenderer playerSprite; private PlayerControls playerControls; private Rigidbody rb; private Vector3 movement; private const string IS_WALK_PARAM = "IsWalk"; // Start is called once before the first execution of Update after the MonoBehaviour is created private void Awake() { playerControls = new PlayerControls(); } private void OnEnable() { playerControls.Enable(); } private void Start() { rb = GetComponent(); } // Update is called once per frame private void Update() { float x = playerControls.Player.Move.ReadValue().x; float z = playerControls.Player.Move.ReadValue().y; movement = new Vector3(x, 0, z).normalized; anim.SetBool(IS_WALK_PARAM, movement != Vector3.zero); if(x != 0 && x < 0) { playerSprite.flipX = true; } if(x != 0 && x > 0) { playerSprite.flipX = false; } } private void FixedUpdate() { if (movement != null) { rb.MovePosition(transform.position + movement * speed * Time.fixedDeltaTime); } } }