Files
Click-PointRPG/Assets/Scripts/NavMeshMovementController.cs

33 lines
726 B
C#
Raw Normal View History

2026-02-10 21:27:46 +00:00
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class NavMeshMovementController : MonoBehaviour
{
NavMeshAgent agent;
void Awake()
{
agent = GetComponent<NavMeshAgent>();
}
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;
}
}