using UnityEngine; using UnityEngine.AI; [RequireComponent(typeof(NavMeshAgent))] public class NavMeshMovementController : MonoBehaviour { NavMeshAgent agent; void Awake() { agent = GetComponent(); } public void MoveTo(Vector3 worldPosition) { if (agent == null) return; agent.isStopped = false; agent.SetDestination(worldPosition); } public void Stop() { if (agent == null) return; agent.isStopped = true; } public bool IsAtDestination(float tolerance = 0.1f) { if (agent == null) return true; return !agent.pathPending && agent.remainingDistance <= agent.stoppingDistance + tolerance; } }