How to let our AI Guards see

Guard AI Part 5

In this article we will give our guards the ability to see. There are various ways to do this. An example would be using Raycast. Another method is using invisible game object in front of our guards that works as a trigger. This will be used this time.

Turn off the Mesh Renderer Component to make the cube invisible.

Turn on Is Trigger in the Inspector

The gameobject is a child of our guard it moves and rotates along.

Finally we create a script “Eyes” to add to all guards. When the player is detected we enable our game over cutscene.

[SerializeField] private GameObject _gameoverCutscene;

private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
_gameoverCutscene.SetActive(true);
}
}

--

--

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
Tristan Engel

Tristan Engel

18 Followers

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.