My journey becoming a Unity game developer: Security Cameras-Changing the color of the camera lights

Rhett Haynes
4 min readNov 14, 2021

Objective: Change the color of the cameras lights to red when the player is caught. Also, stop the camera from rotating when the player has been detected .

Camera light changes to red and freezes in place when the player is caught.

We want to turn the lights to a see through red color when the player is captured. To do this we need access to the Shader component and the Tint Color setting.

Changing the tint color in the Shader component to show what the camera’s light will look like when the player is caught.

We will start by creating a new script name SecurityCamera. Create a new variable Type Game Object name gameOverCutscene which will hold the Game Over Cutscene game object. Use the OnTriggerEnter() function to find IF the tag equals the Player. If it does, we want to get the Mesh Renderer component within a new variable. Then, use that variable to assign it to the Color red. Finally, Set the gameOverCutscene variable to be Active.

Changing the camera’s light color to red through the MeshRenderer.

The code above won’t work because the red color is too intense, and we need to change the Tint Color specifically.

Camera’s light turns red when the player is caught, but the intensity of the color is too strong.

Instead, after getting the Mesh Renderer component we will create a new variable Type Color name color. The values that will be passed in are (.7f, .2f, .2f, .05f) as a new Color which will change to the color red at half the intensity. Then, using the Mesh Renderer component variable Set the Color of the material using the _TintColor setting as a parameter and assigning the color variable’s values.

Changing the tint color to red of the Shader.

Now we have the lights turning red at half the intensity to allow the characters to be seen clearly.

Using the regular Color format to turn the lights red.

There is also another way to change the color of the lights to red. Back in the Tint Color setting, we can use the 32-bit RGBA-255 color values.

Using the RGB 255 values for color changes.

For the color variable, we will use the Color32 Type instead of the regular Color Type. The new Color32 values will be (195, 44, 44, 11) which will still change the lights to red. Everything else in the code will stay the same.

Using the 32-bit color format.

Lights changes to red using the 32-bit format.

Camera lights turns red using the 32-bit color format.

What we want to do next is stop the red light camera when the player is caught. Create another new variable Type Animator to be the handle of the Animator component name anim. After setting the color, disable the Animator attached to the Camera Cone game object using the anim variable. After disabling the Animator, start a coroutine to pause for half-second and activate the gameOverCutscene name AlertRoutine.

Select each Camera Cone game object and drag the actual camera game object with the animator we want to turn off into the Anim variable slot which will be Camera_1.

Assigning the animators of the camera to the lights.

Now the camera will freeze with the red light turned on when the player is caught on camera.

Camera stops when the player is detected.

--

--