Changing Scenes on 2D Collision

So I’m new to scripting and I have a 2D game. I want to change scenes when my player collides with another quad. They both have 2DBox Colliders, the quad’s box collider is checked as a trigger, the player is tagged “Player” and this script is attached to the quad.

using UnityEngine;
using System.Collections;

public class CollisionSceneChange : MonoBehaviour
{
	public string level = "testingscene2";

	// Use this for initialization
		void OnCollisionEnter2D (Collision2D Colider)
	{
		if(Colider.gameObject.tag == "Player");
		Application.LoadLevel(level);
	}
}

it gives me no syntax errors and the game runs but it doesn’t work. I tried with OnTriggerEnter2D but that doesn’t work either. Can somebody please help?

Please do all of the following:

  1. Delete the semicolon at the end of the if statement (line 11).
  2. Change the function back to OnTriggerEnter2D again. OnCollision*** is only called for two non-triggers.
  3. Make sure the player object is tagged Player.
  4. Make sure that collisions are enabled between the layers that the player and the scene change trigger are on.

void OnColliderEnter2D (Collider2D collider)
{
if(collider.tag == “Player”)
Application.LoadLevel(“testingscene2”);
}

I wouldn’t know why you would put “testingscene2” as a string to level.
but your code is fine.

make sure your quad has a rigidbody2D attached to it. and set the gravity Scale to zero.
That is if you want to not make use of gravity for that object.

Make sure the trigger is enabled on just 1 of the objects. (not 2, just 1)

EDIT : Add Debug.Log("its Colliding!); to make sure it is working.

void OnTriggerEnter2D(){
Application.LoadLevel(2);
}
and check if the object where the script is put have a collider and set it to trigger :smiley:

using UnityEngine;
using System.Collections;

public class levelchange : MonoBehaviour {

void OnColliderEnter2D (Collider2D collider)
{
	if(collider.tag == "Player")
		Application.LoadLevel("level1");
		Debug.Log("its Colliding!");
}

}

this is my code but nothing is happening i have no clue why, i have a box collider with is trigger on my object and i’ve also loaded the scenes in build settings