OnCollisionEnter 2d?

Hi i’m making a 2d game with sprites and i have a level where the player (a cube with 2d box collider) has to get a goal (another cube with 2d box collider tagged Goal) and when that happens you go back to the level select but the code doesn’t work. Can anyone tell me why please and if possible tell me a better way to do this.

this is my current code:

function OnCollisionEnter (collision : Collision) {
if (collision.gameObject.tag == "Goal"){

Did you remember to put these scenes into the build settings? Click on File>Build settings. Click add current to the list, add all the scenes to the list. There will be numbers beside them. The number 0 scene will be loaded first. Once you have all the scenes in the build settings then it will work. At least it should…

Well i think that you should do it like this:

function OnCollisionEnter2D (collision : Collision2D) {
if (collision.gameObject.tag == “Goal”){

If this still doesn’t work check if you’re trigger is checked as on.

Check if the object you’re colliding with has a tag “Goal” and if it’s triggered too.

Check if you’re scene is on build setting, if you don’t know how to check go to “File/BuildSettings” and there you should see you’re scene.

If it isn’t there then open the scene and then go to “File/BuildSettings” and press “Add scene”.