
Setting Up the Security Cameras
Adding Rotating Animation and sensors to detect Player
After we get past the Guards, it is time to set up our next obstacle that our Player needs to overcome, the security cameras. To accomplish this we will need to create a new C# script and also create new animation sequence for the Cameras.
Animating the Cameras:
The good thing about animating the rotation only of an game object is that it can be applied to multiple of the same object without consequence. To start, we first need to create an new animation clip, so select the Camera_1 game object and within the Animation window (windows > Animation > Animation) we can start the animation. In the first frame, set the rotation of the Y axis to 45, then at another set interval (ie. 1 second later) set the Y axis to -45. Finally, to make the camera return back to the origin, at another set interval mark the Y axis back to positive 45.
This will make the camera loop back and forth. If the speed of the loop is too fast we can reduce the speed by setting the “Sample Rate” down to either 15 or 10.

Adding Detection to the Camera:
Now we need to make the camera be able to detect the player if they cross the line of sight. Provided in the scene are 3D cones that also rotate with the camera. This cone will be our detection device.

To begin, add an Rigidbody component to the cone and deactivate the gravity setting by unchecking it. In the Mesh Collider make sure that the “Is Trigger” function is turned on.
Create a new script called Security Cameras, and within that script we are going to follow a very similar approach that we have done with the Guards detection ability. We are going to have an void On Enter Trigger event which checks for the Player tag. If the player collides with the object we will trigger an Game Over cutscene of the player getting captured.
To start, make sure that you create a Serialized Field or make the cut scene handle public to gain access to it later. Delete the other unwanted codes (start and Update methods) and add in Void On Enter method. Add a IF statement to check for the player and set the cutscene game object to true.

Back in Unity, drag the new camera script into the 3D cone game object and also drag and drop the captured cutscene.
