# How to enter a level when touching an object

I am working on a project in Unity 4.6.1f1 and I was wondering how can I make a cube touch another cube to go to the next level (the image below)?

!

EDIT: I made a script and put it on the purple cube then enabled "is trigger" on the purple cube, but the blue cube goes right through it.

Inspector:

And the code:

EDIT 5/15/15: I edited my script and I was wondering if I'm doing something wrong.

Your LevelCollider is attached to a Collider that is a trigger. That means it will not call OnCollisionEnter. It will call OnTriggerEnter.

void OnTriggerEnter(Collider other) {
}


That should do ya!

void OnCollisionEnter (Collision col)
{
}


If your character's Collider is a trigger, then you need to use OnTriggerEnter. I.e.:

void OnTriggerEnter (Collider other)
{
}


If neither of these work, try checking these things:

• The character and object are set to collide in the layer collision matrix.

• The scene called "Level1" is added to the build. You can check if it is by pressing Ctrl-Shift-B under 'Scenes in build'.

The command to load a level is Application.LoadLevel(). Call that from an "On Collision" function on the cube.

You can add a box collider (Add -> Physics -> Box Collider) in the inspector.

Then, add a script with a function

 OnCollisionEnter(Collision other)


then add that script to the cube you want to collide with.

• Is this in JavaScript? – kprovost7314 May 3 '15 at 4:55
• Do I create that function then put Application.LoadLevel() in it? – kprovost7314 May 3 '15 at 5:06
• It is c#. And yes, you put Application.LoadLevel() inside the function – Cafn May 3 '15 at 19:00
• I enabled "is trigger" on the collider settings (for the cube that's supposed to take you to the next level) with Application.LoadLevel() and all it does is go right through the cube without leaving the scene. – kprovost7314 May 3 '15 at 23:08
• That Cube has the script added to itself? Post some screenshots of code and inspector – Cafn May 4 '15 at 1:13