using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; using UnityEngine.EventSystems; public class PlayerMovement : MonoBehaviour { [Header("Components")] [SerializeField] private NavMeshAgent agent; [SerializeField] private Animator animator; private float lookRotationSpeed = 8f; void Awake() { agent = GetComponent(); animator = GetComponent(); //input = new CustomActions(); //AssignInputs(); } public void MoveTo(Vector3 point, Action action = null) { agent.destination = point; //replace later action?.Invoke(); } private void Update() { if (!agent.pathPending && agent.remainingDistance > agent.stoppingDistance) { FaceTarget(); } ////SetAnimations(); } private void FaceTarget() { if (agent.velocity == Vector3.zero) return; Vector3 direction = (agent.destination - transform.position).normalized; Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z)); transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * lookRotationSpeed); } public void StopMovement() { agent.destination = transform.position; } //void SetAnimations() //{ // if (agent.velocity == Vector3.zero) // { animator.Play(IDLE); } // else // { animator.Play(WALK); } //} }