Unity - Navmesh event on navigation end

Viewed 5482

Is there a way to raise a flag on the Navmesh navigation end, or to use a callback when it finish?

I want to run a function when my objection reach to the desire position, I can check on every frame update if the navigation has finished but I want a more elegant and efficient solution.

Thanks.

1 Answers

It depends what you mean by "ends", if you want to know when a path is no longer available for the NavAgent, you can use pathStatus, for example you could write:

if(myNavAgent.pathStatus != NavMeshPathStatus.PathComplete) {
  // Do stuff
}

If you me reaching a location such as a "waypoint" you can use myNavAgent.remainingDistance then check if it is less than a certain value.

Here's the unity NavAgent scriptingAPI doc link: https://docs.unity3d.com/ScriptReference/AI.NavMeshAgent.html

If this doesn't work, let me know!

Related