0
votes

I'm trying to load a level when the player passes through the cube but for some reason nothing happens when it passes. I have a cube with components: Cube(Mesh Filter), Mesh Renderer, LevelLoad script and Box Collider with isTrigger ticked. The levelload script looks like this:

using UnityEngine;
using System.Collections;

public class LevelLoad : MonoBehaviour {

    void onTriggerEnter(){

        Application.LoadLevel ("level02");
}
}

My current scene and level02 have been added to the build settings. And in my level02 scene, I also have a cube with box collider but is trigger isn't ticked (I've also tried ticking it but nothing happened). I don't even get errors when I run the game so I'm not really sure what the problem is.

1
Does the player have a collider on it? Also try putting a Debug.Log statement in your onTriggerEnter, that will tell you whether the problem is in the Application.LoadLevel or before.Adam H
I tried adding a box collider to the player but nothing happened.Gina
It could be a letter case issue. OnTriggerEnter has a capital O.Catwood
I'm so stupid. That was it. Thanks a lot.Gina
@Gina No problem, that got me once too. Because it does not break anything, the compiler assumes you are just defining your own method and the physics engine is calling it rather than you directly, its hard to spot.Catwood

1 Answers

1
votes

For a collision to take place, at least one of the colliding objects must have a Rigidbody. So, try adding one to the player.

EDIT: can't believe I overlooked this, but @Catwood noticed that your method is named onTriggerEnter, when it should be OnTriggerEnter. That's probably the issue.