Day 101: Security Camera System Part II

Boqin Zhang
3 min readJun 27, 2023

--

Now that the scene is set up, let’s code a way to switch game views.

Once we’re in TriggerBox (red box), we can press “C” to switch views. Pressing “C” won’t do anything once we’re outside TriggerBox.

Create an empty object (CameraManager) to hold a “CameraManager” script.

These are the variables in the CameraManager script.

The variable, _cameras, holds all the cameras.

The variable _currentCamera is a public int. It controls which camera we designate to set as higher priority later in another script.

The boolean, _canSwitchCams, helps control whether pressing “C” will do anything or not. This is the function that _canSwitchCams controls.

If is _canSwitchCams true and “C” is pressed, we increment _currentCamera by 1 (_currentCamera++) which means the next camera will be our designated camera. We have a nested if-statement to check if we’re within the bounds of the array. If not, we’ll start at camera 0 again.

We rest all the camera’s priorities (SetLowCamPriorities()) and we set the designated camera to a higher priority (SetCurrentCamera()).

We have another script, CameraTrigger script, to control when to use the functions inside the CameraManager script.

When the player enters TriggerBox, we set _canSwitchCams to true. We call the other functions to manipulate the cameras’ priorities.

When the player exits TriggerBox, we set _canSwitchCams to false. We call the other functions to manipulate the cameras’ priorities. We reset _currentCamera to the first camera.

--

--