Big brother is watching — How to create security cameras in Unity

Luke Duckett
2 min readJul 6, 2021

In this article, I will go over a quick and simple method of implementing a security camera system in Unity.

A developer sometimes gets tunnel vision and will code in a solution to a problem when there was a simpler way. Case and point when I was tasked to create a moving security camera the first thing I did was write a script to manipulate the game objects rotation over time. There was a more simplistic approach. Animation.

The first step is to create and add an animation controller for your camera and adding it to the game object.

Now click on the camera and open your animation window and create a new animation.

From here we are going to record a simple rotation over 6 seconds and then have the camera rotate back to the starting position.

The next step is to create a script that will cause the game to be over when the camera spots the player.

In this script, we will stop the camera from moving and turn the colour of the light to red when the player is spotted. I’ve added a simple coroutine that accesses the tint of the material and changes it to a colour assigned in the inspector, we then wait and fire off a game over the action from our game manager. The action triggers our game over the cutscene and hides our in-game guards and player to show the cutscene game objects.

Back on the security camera, ensure it has a collider and rigid body to enable the collisions.

Now we can test our functionality.

That’s all for now.

--

--

Luke Duckett

🎮 First Nations Unity Dev from Wonnarua country 🏞️ | From Player to Lifelong Learner: Crafting Games, Debugging Code, and Embracing New Technology