Using the Camera Triggers in Unity

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

--

--

--

Recommended from Medium

Download In #!PDF Starting out with Visual C# Read

Uninstall Cisco AnyConnect VPN on MAC

Preparing Linux for the future It Really Deserves

What I mean when I say ‘Platform’

Stack of post-its

Let Us Docker 🐳

5 Pandas Tricks You Should Start Using in 2021

Face verification with Azure Face API

iOS 11 & Swift 4 Udemy tutorial (notes)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store