using UnityEngine; [RequireComponent(typeof(Rigidbody))] public class PlayerController : MonoBehaviour { [SerializeField] private float moveSpeed = 5f; [SerializeField] private float rotateSpeed = 12f; [SerializeField] private GameManager gameManager; private Rigidbody body; private Vector3 moveDirection; private void Awake() { body = GetComponent(); } private void Update() { if (gameManager != null && !gameManager.IsPlaying) { moveDirection = Vector3.zero; return; } var horizontal = Input.GetAxisRaw("Horizontal"); var vertical = Input.GetAxisRaw("Vertical"); moveDirection = new Vector3(horizontal, 0f, vertical).normalized; if (moveDirection.sqrMagnitude > 0.001f) { var targetRotation = Quaternion.LookRotation(moveDirection); transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotateSpeed * Time.deltaTime); } } private void FixedUpdate() { var velocity = moveDirection * moveSpeed; body.velocity = new Vector3(velocity.x, body.velocity.y, velocity.z); } }