How to change scenes using box collider and first person controller?

I have a simple scene with a cube in the middle. I want to make it so that when my first person controller runs into the cube the game will automatically transition to the next level.

I made the cube a box collider and checked “is trigger”

I made this script:

var target : Collider;

function OnTriggerEnter(cubeTrigger : Collider)
if (cubeTrigger == target)

{ Application.LoadLevel ("longhouserealm"); 



and attached it to the cube. (longhouserealm is the name of the scene that i want to go to)

Under the cube’s trigger script window, I assigned the First Person Controller as the target.

I have both of the scenes in my Build Settings list.

Buttttt it doesn’t work. When i walk through the cube, nothing happens. The only thing that changed is that the cube is now penetrable instead of solid.

I’ve been trying to figure it out by patching together tutorials all day… I’m a newbie and would appreciate any advice or alternate methods for changing scenes!! Thank you!!!

i would suggest start using tags. you can have different trigger events based on the name of the tag.
Click on your prefab/object door . In the Inspector at the top you should see Tag with a drop-menu next to it (possibly saying Untagged). Click on dropbox, at the bottom Click on Add Tag …

In the Tag Manager, expand the Tag menu (click bkack arrow). In the next empty space, add your tag.

i.e. if there is no writing next to Element 0, click on it and write Door .

OK so you made a new tag , now you have to put it on the door. again click on door prefab/object. now in the inspector click on tag, now Door should be on the list. Click on it, the door should now have the tag Door.

Use this in your OnTriggerEnter function :

function OnTriggerEnter (cubeTrigger : Collider)
	Debug.Log ("OnTriggerEnter : cubeTrigger.tag = " + cubeTrigger.tag); // shows the tag of the trigger
	// if tag is door
	if (cubeTrigger.tag == "Door")
		Application.LoadLevel ("longhouserealm");