Loading a new level upon collision isn't working?

Ya’know the generic loading a level when the player collides with an object tagged as enemy, it isn’t working in the 2d environment (well at least what i boil it down to).

I have used the technique when working on a 3d game a while ago and it worked perfectly but it just fails to work, I have tried everything. I have even tried the script in Unityscript and in C# and neither have worked. I have looked throughout Unity and i cannot find anything wrong with things such as tags.

The player is using a 2D Box Collider and a platformer character controller script.
The enemy is a static object with a 2d box collider.

Any help would be appreciated. I can supply the scripts if you would like but according to other forum posts, the scripts I am using are the exact same as the ones everyone else is using to load a level upon collision.

thanks.

Are you getting any errors? Are you sure the level load works in a different context (e.g. link it to a keycode in Update)?

It gives me no compiler errors. I have tried putting into the update function but I believe i got the code wrong for the bool’s and stuff. (I am not a programmer)

Can someone give me guidance?

function OnCollisionEnter (other : Collision) {
  if(other.gameObject == "Enemy"){
boolean playerIsDead = true;
}


}

function Update () {

if (playerIsDead == true){

Application.LoadLevel(Application.loadedLevel);



}


}

Okay, right off the bat, if you’re using a BoxCollider2D, you need to use OnCollisionEnter2D. OnCollisionEnter is for 3D and will never be called if you’re using 2D physics. That might solve your loadlevel-in-collision problem.

Also, since you’re declaring “playerIsDead” in the function, it’s only in scope for that function. You want to declare it outside the function, so that the Update function can use it.

I see. I will test the OnCollisionEnter2D when I get a chance, ill bump this thread if it works/or not. Thanks for the tip.