Nav Mesh Agent Has Arrived#
Navigation / Nav Mesh Agent / Nav Mesh Agent Has Arrived
Description#
Returns true if the Nav Mesh Agent has no path left to travel
Parameters#
| Name | Description |
|---|---|
| Nav Mesh Agent | The Nav Mesh Agent component checked |
Code#
using System;
using UnityEngine;
using UnityEngine.AI;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Title("Nav Mesh Agent Has Arrived")]
[Category("Navigation/Nav Mesh Agent/Has Arrived")]
[Description("Returns true if the Nav Mesh Agent has no path left to travel")]
[Image(typeof(IconNavmeshAgent), ColorTheme.Type.Red)]
[Keywords("Navigation", "NavMesh", "AI", "Agent", "Reached", "Destination", "Done")]
[Parameter("Nav Mesh Agent", "The Nav Mesh Agent component checked")]
[Serializable]
public class ConditionNavMeshAgentHasArrived : Condition
{
[SerializeField] private GetGameObject m_NavMeshAgent = new GetGameObject(
new GenTypeGameObject_NavMeshAgent()
);
protected override string GetTitle(GameObject source)
{
string member = TextUtils.ThemeAsKeyword("Has Arrived");
return $"{this.m_NavMeshAgent} {member}";
}
protected override bool Run(Args args)
{
NavMeshAgent agent = this.m_NavMeshAgent.Get<NavMeshAgent>(args);
if (agent == null || agent.pathPending) return false;
return agent.remainingDistance <= agent.stoppingDistance;
}
}
}