Guards have eyes

Hal Brooks
2 min readAug 24, 2021

Objective: Add a detection system to guards allowing them to see Darren.

Create a 3D cube as a child of the first SecurityGuard, and disable its mesh renderer. On its box collider, check is trigger to allow it to detect other game objects, renaming it Eyes. The required rigidbody is on the Player.

Eyes for the guards.

Duplicate the Eyes and add one to each guard, renaming each to Eyes.

Hierarchy for guards and eyes.

Adjust the Eyes position to look similar to that shown below for each guard by selecting edit collider toggle.

Vision box for guard’s eyes.

Create an Eyes C# script and attach it to all three Eyes game objects. Use a SerializeField to assign the Captured_Cutscene to the _gameOver game object, as shown in the top figure. Void OnTriggerEnter is used to detect other game objects, and if that object is tagged as Player then the Captured Cutscene is set to active and plays.

Eyes script attached to Eyes of the guards.

Now the security guards can see and capture Darren.

Darren is captured!

This article uses assets from The Great Fleece by GameDevJon on the Unity Asset Store.

--

--