How to enter a level when touching an object

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.

Solutions/Answers:

Answer 1:

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

Try adding this to LevelCollider:

void OnTriggerEnter(Collider other) {
     Application.LoadLevel("Level1");
}

That should do ya!

Answer 2:

Detect collisions with OnCollisionEnter then load your level there. I.e.:

void OnCollisionEnter (Collision col)
{
    Application.LoadLevel("Level1");
}

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

void OnTriggerEnter (Collider other)
{
    Application.LoadLevel("Level1");
}

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’.

Answer 3:

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

Answer 4:

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.

More info in here: https://unity3d.com/learn/tutorials/modules/beginner/physics/colliders-as-triggers

References