Can't get my nextlevel script to work in my 2D game.

I made a simple nextlevel script but it won’t trigger when my character interacts with it, it just walks straight through it.

#pragma strict

function Start () {

}

function OnTriggerEnter () {

	Application.LoadLevel("level-1");

}

So I have applied a collider and the script to the door sprite but it doesn’t work and my character walks through it.
My character has a box collider for the head and body and a circle collider for the feet. I also have the level in my build settings.

I notice the Z is -.1 on the door. Are you sure the 2 colliders are overlapping at some point?

The character is also on -.1

I can also give you the project if you want…

Not sure about changes with 4.3 sprites but OnTriggerEnter generally has a collider parameter.

Scott

bump :confused:

Did you try adding the collider parameter to your OnTriggerEnter?
function OnTriggerEnter (other : Collider) { }

Have you put a Debug.Log call in the event handler to verify its being called. My guess is that the prototype doesn’t match and isn’t being called, thus your Application.LoadLevel isn’t being executed.

If you’re trying to get notification from a 2D trigger collider, your method should be “OnTriggerEnter2D”, not “OnTriggerEnter”.

Jeff

1 Like

Thanks! You are amazing!
And thank you everyone for the fast responses, what a great community for a newbie.

Awsome! Thanks!