How do I get the MainCamera to trigger application.loadLevel when it hits a collider?

Hi all,

I am working on my first game in Unity and at the start I have a camera moving around the starting area which I want to trigger the main level to begin once it gets to a specific point.

The code I am using is…

function OnTriggerEnter (Collision : Collider)

{

if(Collision.gameObject.tag == "MainCamera")

{

Application.LoadLevel("level2");

}

}

I have attached this script to an EmptyGameObject with a Trigger Collider, I have animated the MainCamera to enter this trigger box at the end of its cycle.
The main camera is tagged as ‘MainCamera’ to match the tag in the script.

When I do this nothing happens, however if I use a FirstPersonController instead, it works fine, as soon as I walk into the trigger collider the next level loads.

I do not want a FirstPersonController active though, as it is an intro camera pan where I want no interaction from the player.

I have also tried using other GameObjects to trigger the next level, but these do not activate the trigger either, it only seems to be the FirstPersonController that will trigger the next level to load when it hits the collider.

Can anyone offer any advice on this please?

Many thanks in advance.

My first thoughts, you might want to try if(Collision.tag == “MainCamera”) rather than if(Collision.gameObject.tag == “MainCamera”). An easy way to tell what is colliding with your GameObject is by print(Collision.tag) or print(Collision.name). Other than that you might want to double check the tag of the Camera and also make sure there is a collider on there.

Triggers detect rigidbodies or CharacterControllers. Create any simple object - a cube, for instance - and add a CharacterController to it using Components/Physics/Character Controller menu. Child the object to the camera, and reset the object’s position. Presto! Your camera will be detected by any trigger!

Don’t mind about the CharacterController you’ve added to the camera: it’s just a component, not the First Person Controller (the F P Controller is a prefab; it has its own CharacterController, and that’s why it activates the trigger).