Creating Security Cameras in Unity

Stealth Game & Cinematography

Objective: Create a security camera behavior.

First create a script for the security camera so that we can create a behaviour for the camera

Inside the script, add a reference variable which will start a gameover cutscene when it detect the player.

Create a coroutine so that the game waits for half a second before the cutscene starts to give enough time for camera to display that it has detected the player by changing the camera ray color.

Now create a trigger enter function which detects when player enters the collider then sets the player to inactive, changes the color to red, sets all the security guards to inactive and disables the animator so that camera stops rotating.

Then add this script to the gameobject with collider inside the security camera as well as add the rigidbody component and set the trigger to true.

You can also animate the camera by rotating the value in y-axis.

Now open the animator and duplicate the animation and rename it to reverse and make transactions between them. Then change the speed value inside the reverse animation to -1.

You can then control the speed of camera rotation through samples.

And this is how it looks.

Unity Developer