How to Build an Interactive Security Camera System in Unity

Chris Hilton
5 min readFeb 28, 2022

Objective: To show you how to build an interactive security camera system in Unity using different Cinemachine cameras.

Interactive Security Camera System

Let’s say you have a scene and the main character needs to move past a bunch of security cameras (possibly down some hallways) and you have access to watching them. Now let’s take this basic scene, build it and play it out using primitive assets and Cinemachines cameras. For prototyping purposes this is a wonderfully quick way of figuring out whether the scene/gameplay will play out how you expect it to.

I will also create a trigger switch in the middle of the room so that when the character stands on it, it will automatically turn all the cameras on and subsequently turn them off when they step off the trigger, deferring back to the original 3rd person follow camera that we have setup initially.

Stepping on the trigger switch will also give the player the ability to press the ‘C key and cycle through the various cameras.

Example of the Scene

To get started I am showing a quick snapshot of the scene and how I have it all setup:

Basic primitive scene

Add 3D Character

Let’s add our 3D character from the Unity Asset Store as this is the quickest and easiest solution for this.

Head to the Unity Asset Store for your ‘Starter Assets — Third Person Character Controller’. Get this downloaded and installed into your scene via Unity’s Package Manager:
Window → Package Manager → Packages: My Assets → Starter Assets — Third Person Character Controller → Import.

Installing Third Person Character Controller Starter Asset via Package Manager in Unity

With this installed, head to the top tab and look for Tools → Starter Assets → Reset Third Person Controller Armature.

Tools → Starter Assets → Reset Third Person Controller Armature

This will instantly create a working 3rd person character in the scene when you press Play!

Building the Environment

Let’s make this super simple and just create 3 cubes that are spaced apart to reflect hallways and adjust their scale to your liking.

Also create a cube in the centre for the player to step on. Make sure that the Box Collider component is added and that ‘IsTrigger’ is ticked. When this is done, make sure to turn the Mesh Renderer component off so we don’t see the cube.

Adding some Cinemachine Cameras

Referring to our initial screen snapshot, let’s now create our 3 Cinemachine cameras by simply adding them via the top tabs, Cinemachine → Virtual Camera…

For my project I am going to have one basic static camera, one point of view (POV) camera that has restricted movement on both the vertical and horizontal axis and finally for the last one, it will be an automatically panning camera.

Camera 1

This will be the static camera that won’t have a Follow or Aim target.

Cinemachine → Create Virtual Camera.

Move to the location you like, I have moved it to position 1 with this view:

Static camera set up at position 1

I have only need to adjust the ‘Lens — Field of Viewsetting to achieve this view.

Camera 2

This will be the Point of View (POV) camera with restricted movement.

Cinemachine → Create Virtual Camera.

Again I have adjusted the ‘Lens — Field of Viewsetting for this camera and also set the ‘Aimsetting to ‘POV’ to achieve this view:

POV camera moved to position 2

Now let’s set the restricted movement of the camera so that when the player is cycling through the cameras and get to this one, they will notice as they move the mouse on the X and Y axis that it will stay within a set range:

POV restricted camera settings
POV camera with a restricted range on the X and Y axis

Camera 3

This camera will be the automatically panning camera that will simply move left to right. In this instance we will use a Blended Camera List.

Cinemachine → Create Blend List Camera.

Let’s set this up at position 3 and we are going to need 2 children for the Blend List. Let’s also set this to loop so they will continue this behaviour.

Lastly, let’s choose our blend options and how long we want to hold for at each camera position:

Blend List Camera setup
Blend List cameras panning from left to right

When the player presses ‘C’ for the fourth time, they will go back to the original third person camera view.

Creating Code for Trigger Switch Functionality and Camera Cycling

We are going to need 2 scripts for this.

The first is the ‘TriggerSwitchscript that will go on the trigger box and will activate the cameras whilst allowing for player input to switch between cameras as they stand on the trigger.

The second is the ‘CameraManagerscript which is going to go on the ‘CameraManagergame object and will hold a reference to all the cameras in an array, allowing us to be able to grab the Cinemachine camera components and easily reset/adjusting the priority levels of the cameras using If/Else statements and a For Loop.

TriggerSwitch Script

TriggerSwitch script

CameraManager Script

CameraManager script
CameraManager game object with SerializeField array of VCams

Let’s Test It Out!

Interactive Security Camera System

--

--