using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour { [SerializeField] float moveSpeed = 5f; [SerializeField] Rigidbody2D rb; [SerializeField] Animator animator; Vector2 movement; private void Update() { movement.x = Input.GetAxisRaw("Horizontal"); movement.y = Input.GetAxisRaw("Vertical"); animator.SetFloat("Horizontal", movement.x); animator.SetFloat("Vertical", movement.y); animator.SetFloat("Speed", movement.sqrMagnitude); } private void FixedUpdate() { if (rb != null) { rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime); } else { Debug.LogError("No Rigidbody2D found in PlayerMovement.cs"); } } }