Security Cameras Part 2!

Objective: Create functionality to the security cameras!

Last tutorial we placed security cameras and gave them panning animation. In this tutorial we are going to add functions to the cameras. What do we want the cameras to do? We want them to detect the player, we also want to stop the animation when the player is spotted and why not turn the color red when it detects the player.

Lets start with detecting the player. Create a script for your camera, and depending on how your camera asset is set up, you want to place the script on the object under your camera parent object that has a collider.

This is going to be a trigger script so we can delete everything inside the script.

We need to start the on trigger enter method and set the scenario for if the collider is the player.

So, when the camera detects the player what do you want to happen. Well, for me I want this to be an instant game over. So we need a handle to the game over cutscene.

No you can drag the game over cutscene into the inspector. With this done, in the scripts we are going to activate the cutscene.

With this, if the player is seen by the cameras the game is over. The next thing we wanted to do was stop the animation of the cameras so when the player is detected the camera stays looking at the player. We need access to the animator so create a handle.

Now when the player is detected turn the animator off.

With the animator disabled the camera will no longer pan. From here we noticed that the camera is hard to notice when the cutscene is automatically started. To give a slight break in this we can implement the use of a coroutine.

In this coroutine we want to wait for half of a second and then call the game over cutscene.

All that is left of to call the coroutine. We want to call the coroutine if the player is detected.

When the player is detected the camera will stop on the player and half of a second later the game over cutscene will play. This is a good stopping point, In the next tutorial we will finish with the security cameras with changing the color from their natural color to a red when the player is detected. I’ll see you in the next tutorial!