Giving the Guards Eyes
A lot is going on in the picture above but let’s explain it. This is a picture of the first guard in the scene. The green “lines” that make shapes are Colliders. The one around the guard itself is the NavMeshAgent. It has a capsule collider shape, this allowing this guard to move around the NavMesh. The main focus though is the Box Collider that is in front of the guard.
A collider is just that: It’s something that “collides” with another object. In this instance though we’re using it as a Trigger. A trigger is a way to activate something. Using this trigger we’re able to activate the Game Over Cutscene that was made previously.
The script for this is pretty straightforward. The script is placed on the object that is acting as our eyes. Grabbing the box collider component we get our reference for the box collider. Using the On Trigger Enter method, which is called when something enters the range of the trigger, we can get information about the other object using the “Other” variable that is passed in. If wanted we could even get components from that object but for this case we just want to grab the tag on the Other object and check if it’s the player. If it is then we activate the Game Over Cutscene because they were caught.
With that all the guards are set up and can see. So on to the next. A distraction system.