Now our Player passed through those guards, we are facing 2 security cameras. However, it seems not working at all. With its cone shape detecting area, it would be easy to make these cameras work again.
In this article, we will bring these cameras come alive.
First we need to figure out where is the detecting area. In Hierarchy, there is a CameraCone under the camera gameobject. Select it and there should have 1 collider in it.
That is what we use to detect the Player. Add a Rigidbody to both of the CameraCone and disable gravity. Then we can create a new script to both CameraCone.
In this script, it will handle the collision with Player and enable the cutscene.
This function is the same as in GuardAI script. Play it and Player should get caught when enter the CameraCone.
Now we should make cameras moving. To move the cameras, we should make a animation to the body of cameras, which is the parent gameobject of CameraCone.
Select one of them, and create a new animation. In the Animation tab, press recording and adjust the rotation on Y-axis.
Them we can adjust the looping of animation. Open Animator tab while Camera_1 is selecting in Hierarchy. The default state of animation should be the one you created. Copy the state and paste one in Animator, and rename it by adding a “reverse” in the end.
Now, let’s set the transition from the origin to reverse. And also create a transition from reverse to origin.
Select the reverse one, in the Inspector, set the speed to -1. This would make the animation plays as backward.
Back to game scene, play the game and now the cameras should move smoothly.
All done! Now we have 2 functional security cameras!