I’ve been trying to use NavMesh.FindClosestEdge to find the waypoint closest to the position newDirectionVector, but I keep getting an error. I’ve never used FindClosestEdge with the navMesh before so I really don’t know what’s wrong.
Assets/Scripts/Enemy/EnemyAI.cs(169,50): error CS0176: Static member `UnityEngine.NavMesh.FindClosestEdge(UnityEngine.Vector3, out UnityEngine.NavMeshHit, int)' cannot be accessed with an instance reference, qualify it with a type name instead
void Search()
{
newDirectionVector = player.transform.position + relativePos;
// Set an appropriate speed for the NavMeshAgent.
nav.speed = chaseSpeed;
// If near the next waypoint or there is no destination...
if(nav.destination == lastPlayerSighting.resetPosition || nav.remainingDistance < nav.stoppingDistance )
{
// ... increment the timer.
chaseTimer += Time.deltaTime;
// If the timer exceeds the wait time...
if(chaseTimer >= chaseWaitTime)
{
for(searchIndex = 0; searchIndex < searchWayPoints.Length; searchIndex ++)
{
NavMeshHit hit;
if (mesh.FindClosestEdge(newDirectionVector, out hit, 1))
{
searchWayPoints[searchIndex].position = hit.position;
}
}
// Reset the timer.
chaseTimer = 0;
}
}
else
// If not near a destination, reset the timer.
chaseTimer = 0;
// Set the destination to the patrolWayPoint.
nav.destination = searchWayPoints[searchIndex].position;
lastPlayerSighting.evasion = lastPlayerSighting.resetPosition;
}