//------------------------------------------
public IEnumerator AIPatrol()
{
//Loop while patrolling
while (currentstate == ENEMY_STATE.PATROL)
{
//Set strict search
ThisLineSight.Sensitity = LineSight.SightSensitivity.STRICT;
//Chase to patrol position
ThisAgent.Resume();
ThisAgent.SetDestination(PatrolDestination.position);
//Wait until path is computed
while (ThisAgent.pathPending)
{
yield return(null);
}
//If we can see the target then start chasing
if (ThisLineSight.CanSeeTarget)
{
ThisAgent.Stop();
CurrentState = ENEMY_STATE.CHASE;
yield break;
}
//Wait until next frame
yield return(null);
}
}