How to Build an Interactive Security Camera System!

addam davis
5 min readMar 9, 2023

--

Objective: Create a variety of camera for the player to interact with.

In this tutorial we are going to be creating an interactive camera system. The goal in this is to create a spot on the map that allows the player to press a key and access the surrounding cameras. To begin this, I have created four Cinemachine Virtual Cameras. One being a 3rd person camera that follows the player, and the other three are positioned to be security cameras.

I have already covered how to create the virtual cameras I use in this tutorial, so we are going to focus on the interactive system instead. The cameras I used are a POV, a blend list camera, and a static camera.

After placing your cameras in your scene, we need to create a new script to control the camera settings. Since we need to access Cinemachine we need to add the Cinemachine library.

Next, we need a couple variables. First, we need an array of game objects for the cameras.

Then we need two public variables, an int and a bool. One to track the current camera and a bool to control when the player’s input can be effective.

When we trigger the camera access to the player, I want to set the priority of every camera in the scene to be 10. I use a for each loop to cycle through the cameras and two if statements for the type of cameras that are available. Since I used a blend list camera, I need to use a specific search for blend list cameras.

Once this is done, we need to set the current camera to the next camera.

We can now go back into Unity and create an empty object “CameraManager” and attach the camera setting script. In the inspector you need to add game objects and assign your cameras to them in the order you want them to cycle through with the 3rd person camera being set to zero.

Let’s create another script “CameraTrigger.” This will handle all of camera switching triggers. The only two methods this needs is an On Trigger Enter and On Trigger Exit. Also, the only variable we need a variable for the camera settings component.

In the Enter method we are calling on the camera setting and setting the bool to true, calling the method to set the priority low, set the current camera to 1, and calling the set camera method.

The Exit method we are calling both the methods again, setting the bool to false, and setting the current camera to zero.

In Unity create a cube. place this in the scene, this will be the location where you want your player to access the cameras. In the inspector set to trigger so the player can walk into the cube.

We are almost finished, we need to go back into the camera setting script and in the update method we need to create an input check. We need to make sure the bool is set to true, and from there we need to check if the player pressed the C key.

When the player presses the C key we are going to add 1 to the current camera int. Immediately after that we are going to check if the int is larger than the amount of cameras available it will be reset to camera 1. Then we are going to call the low priority method and the set current camera method. This will set the camera, grab the Cinemachine component, and set the priority.

With these done we can go back into Unity and test the results.

Everything works, however, I don’t like the ease out transitions. Instead I would like to cut from camera to camera. To do this select the main camera and under the Cinemachine brain change the default blend to cut.

Check the results.

Perfection! Now you know how to create an interactive camera system. Don’t be afraid to experiment with you own camera setup and I’ll see you in the next tutorial!

--

--