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

Android Architecture Components — LiveData and Room in Action

My experiences at Grace Hopper Conference, 2018

Step into the GAMESTATE!

What the hell is the cloud?

The performance of languages doesn’t matter.

Breaking up with a Monolith

COMMUNICATION BETWEEN ARDUINO AND RASPBERRY PI USING NRF24L01

Leecode 949. Largest Time for Given Digits

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
Christian Carter

Christian Carter

More from Medium

Galaxy Shooter — Shooting Lasers

Unity Profiler- Game Dev Series 144

Adding Emissions to Custom Textures

Creating Elevator in Unity — Part 3: Moving Elevator.