Guards have eyes

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.



Unity Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store