Hey guys, I have a script it works as is, but I can’t seem to add a random pause at each waypoint. Basically right now he walks to each way point and moves on, I am trying to make him pause at each waypoint, Such as sometimes he will be standing there for 5 seconds, other times he might be standing there for 30 seconds before moving on. Any ideas? A timer of sorts? Also if you are a c# genius, I am trying to make him walk to a random waypoint instead of a set path. : 3
void Patrolling ()
{
// Set an appropriate speed for the NavMeshAgent.
nav.speed = patrolSpeed;
// If near the next waypoint or there is no destination...
if(nav.destination == lastPlayerSighting.resetPosition || nav.remainingDistance < nav.stoppingDistance)
{
// ... increment the timer.
patrolTimer += Time.deltaTime;
// If the timer exceeds the wait time...
if(patrolTimer >= patrolWaitTime)
{
// ... increment the wayPointIndex.
if(wayPointIndex == patrolWayPoints.Length - 1)
wayPointIndex = 0;
else
wayPointIndex++;
// Reset the timer.
patrolTimer = 0;
}
}
else
// If not near a destination, reset the timer.
patrolTimer = 0;
// Set the destination to the patrolWayPoint.
nav.destination = patrolWayPoints[wayPointIndex].position;
}