The TargetPosition
property of the NavMeshAgent
class represents the desired destination for the agent on the navigation mesh. It is a nullable Vector3
, meaning it can hold a valid position or be null if no target is set.
The TargetPosition
property of the NavMeshAgent
class represents the desired destination for the agent on the navigation mesh. It is a nullable Vector3
, meaning it can hold a valid position or be null if no target is set.
Use the TargetPosition
property to set or get the target position for the NavMeshAgent
. When setting this property, the agent will attempt to navigate towards the specified position on the navmesh. If the property is set to null
, the agent will not have a target to move towards.
// Create a new NavMeshAgent instance NavMeshAgent agent = new NavMeshAgent(); // Set the target position for the agent agent.TargetPosition = new Vector3(10.0f, 0.0f, 5.0f); // Check if the agent has a target position if (agent.TargetPosition.HasValue) { Vector3 target = agent.TargetPosition.Value; // Perform actions with the target position }