Description
The AgentPosition
property of the NavMeshAgent
class provides the current position of the agent within the navigation mesh. This property is updated with the agent's position regardless of the UpdatePosition
setting, allowing you to access the agent's position even if automatic position updates are disabled.
Usage
Use the AgentPosition
property to retrieve the current position of the NavMeshAgent
in the world. This can be useful for custom logic that requires knowledge of the agent's position without relying on automatic updates to the GameObject's position.
Example
// Example of accessing the AgentPosition property
NavMeshAgent agent = new NavMeshAgent();
Vector3 currentPosition = agent.AgentPosition;
// Use the current position for custom logic
if (currentPosition.z > 10.0f)
{
// Perform some action if the agent is beyond a certain point
}