// method called when status is IDLE protected virtual void idle() { if (idleWaiting) { idleTimer -= Time.deltaTime; } switch (idleType) { case IdleType.NONE: // In this mode, I have to stay in my originPos, so if I followed the player, I have to return home. // If I'm so close to my originPos if (fov.distanceTo(originPos) < PathReachingRadius) { // I rotate to the originRot transform.rotation = Quaternion.Slerp(transform.rotation, originRot, Time.deltaTime * rotationSpeed); } else { // else, I go in my originPos SetNavDestination(originPos); } break; case IdleType.PATROL: // In this mode, if I have a patrol path component attached to me, I follow its node. if (patrolPath) { // if I reached the path destination I go to the next patrol path node if (agent.remainingDistance < PathReachingRadius) //fov.distanceTo(GetDestinationOnPath()) <= { m_PathDestinationNodeIndex = (m_PathDestinationNodeIndex + 1) % patrolPath.PathNodes.Count; SetNavDestination(GetDestinationOnPath()); } } break; case IdleType.RANDOM: // In this mode, I can move randomly // I set a random destination and I go there, // When I arrive there, I wait 'IdleTime' seconds // and then I will set a new random destination if (idleTimer < 0) { idleWaiting = false; idleTimer = 0; setRandomDestination(); } else if (!idleWaiting && fov.distanceTo(randomDestination) < PathReachingRadius) { idleWaiting = true; idleTimer = idleTime; } break; } // if I see the player, I pass in WARNED state if (fov.isPlayerVisible) { idleTimer = -1; idleWaiting = false; agent.stoppingDistance = minDistanceToAttack; fov.viewRadius *= 1.5f; ChangeStatus(Status.WARNED); } }