Easy Security Cameras in Unity
This article will show how to make a security camera that animates and when the Player enters the camera’s vision cone, it stops animating and turns red.
The security cameras are going to oscillate from side to side.
The vision cone has the trigger collider and script attached.
The SecurityCamera script needs variables for the cutscene GameObject to activate, the amount of time to delay before the cutscene, the Color to change to when the Player is detected, a reference to the parent’s Animator to stop the animation, and a reference to the MeshRenderer so we can change the Color of the vision cone.
When the Player enters the security camera’s vision collider, the Color changes to the alert color. The Animator is disabled to stop the movement, and the Coroutine is started for the cutscene delay. We are disabling the Player GameObject for the cutscene, so it is not visible in the background.
In Unity, we hook up the cutscene and set the Color alpha.
When the security camera spots the Player, the vision cone turns red and starts the cutscene after a short delay.