The enemy patrols in a particular path. When he sees the player, he would try to chase him. If he can’t catch with the player, he would go back to patrol.
The sight of enemy
Create an empty game object named EnemySight. Add a sphere collider to it, adjust the radius, and set it as Trigger.
Set the sight game object as the child of the enemy. Give it a script named EnemySight. The script can judge whether the player is inside the sight of the enemy or not. In Enemy script, it will be used as the option if the enemy chase the player or patrol.
Patrol
In enemy behavior script, EnemyPatrol, use enemysight to control the enemy patrol status. Set stopping distance in NavMeshAgent component inspection to a acceptable value.
The statuses of the enemy can be switched between patrol, chase, and other behaviors. Use sight, distance to the player, and other parameters to determine the status.