Using the Camera Triggers in Unity

Christian Carter
2 min readOct 29, 2021

--

This tutorial will cover how to use camera triggers to adjust your camera angles in Unity. Do to this you should already have your camera triggers and your camera angles set up. Create a script called CameraTrigger. Assign it to all of your camera triggers. Also make sure all of your camera triggers have a rigid body and uncheck Use Gravity on them. Also Make to to check Is Trigger. Otherwise they will not actually trigger.

Open the script you just created. You will not need the start or update functions so you can remove those. Add an OnTriggerEnter function and check if the other collider has the Player tag.

private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
Debug.Log(this.name);
}
}

Next, create a variable that will hold the transform for the camera position you want to switch to.

public Transform myCamera;

Then assign the cameras to each of your triggers.

Next in your script update the main camera to match the transform and rotation of your camera transform that is attached to the trigger.

private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
Camera.main.transform.position = myCamera.transform.position;
Camera.main.transform.rotation = myCamera.transform.rotation;
}
}

Now as your player moves through the game the camera will adjust as you move through the triggers.

-Chris

--

--