Initial commit
This commit is contained in:
32
Assets/Scripts/NavMeshMovementController.cs
Normal file
32
Assets/Scripts/NavMeshMovementController.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user