We are a little lacking in security, let’s beef it up!
Objective: Creating Security Cameras in Unity
We are meant to be looking after the Beatrice Auction House, how can we do that without some sort of cameras working? Time to fix them up so they are working!
This one we have been over a couple of times now, so we can just rush through it a bit. I will list it all out then leave a gif with me doing it all.
We will want the camera and the cone to rotate over time, so we can add the animator to that. After adding the animator and making a controller for it, or clicking create in the animation window, go to the first frame and set its rotation. Move across the dopesheet a bit and then change the rotation to Negative of the first number eg, 45 then -45 (on the Y-axis)
To make it so it doesn’t just go 1 way, we can set up the animator to do that. Open the animator window and drag in another one of the animated camera clip we just made. Make a transition to and from the new clip along with changing the speed to -1 on the new clip. Lastly, select the clip in the project tab and uncheck the loop time.
To slow it down by spacing out the animation frames or dropping the sample rate.
Animation is done!
Having it moving is all good and well but if the player can still walk through it with nothing happening, it’s a no-go.
In this one, we will be working with the cone from the camera.
Since it already has a collider, all we need to do with it is make sure that “Is Trigger” is on. Next, add a rigid body and remove gravity, we don’t want the cameras falling to the ground when the game starts, as funny as that would look.
Now all that is left is a script to add to the cone. I named mine SecurityCamera, super original, I know.
This one is super short. After removing the start and the update methods, we can make a variable to store the game over cutscene and then use OnTriggerEnter to detect if the player has walked into the cone and set the game over cutscene active.
After dropping the script on the camera’s cone and adding in the game over cutscene, we can test it out!
Ahhh, we can feel so much safer knowing the cameras will pick up if someone tries to sneak in. See you in the next one!!