Create a patrol/Chase/Attack Script with a certain view range

Hello !

I’m new to coding, so I don’t understand much yet. I have two scripts on my GameObject (an enemy).

The script on the left is to tell the enemy where to patrol by following waypoints I have placed on my map

The script on the right is to determine the Field of view, so the enemy only see inside a specific area

Both are working perfectly fine, but I wanted to know if there was any way of combining these two scripts to create a third one that would include chasing the player when “in sight” and going back to patrol when the player isn’t visible anymore ?

If you also know a way to have a single script that would include patrol (with waypoints I can place), chasing, attacking and going back to patrol, that could also be wonderful ! (All the scripts I have found so far don’t specify a “field of view”, but instead use a sphere with the enemy in the middle to detect the player :frowning: )

I apologize if anyone has already asked the exact same question, but I haven’t found anything that could answer my question

Thank you in advance ! :smiley:

use float enemyDis = Vector3.Distance(this.gameObject.transform.position, enemyLocation.position);

if canSeePlayer is false and Distance > searching range, then go patrol.
if Distance < attack range, attack,
in between, go chasing.