Next Level on collision
I'm trying to write a script so that when you collide with the object at the end of a 2D platformer you get to the next level, however I attached it to the object (the object has a rigidbody2d and box collider attached, and "is trigger" ticked) but nothing happens
The script is something like this
#pragma strict
import UnityEngine.SceneManagement;
public class SceneManagement extends MonoBehaviour {
function OnTriggerEnter (Player: Collider) {
SceneManager.LoadScene("Level 2", LoadSceneMode.Single);
}
}
No idea where I'm going wrong here
Answer by UnityCoach · Jan 05, 2017 at 01:19 PM
If it's 2D, use OnTriggerEnter2D (Collider2D other) {}
That did it, thank you. Once more another case of not seeing the forest because I'm stuck looking at trees
:) yeah, it's always tricky with "message" methods, as you don't get an error if you misspell or misses them. It's good practice to simply put a Debug.Log() in just to see if you ever get in the method.
Your answer
Follow this Question
Related Questions
In the next scene show the score using player prefab before next level 1 Answer
Use a string to call a class 2 Answers
How to, with a button, switch to another level when all items are collected? 1 Answer
How can you load next the level after you destroy the last clone c# 1 Answer
On collision enter next scene 2 Answers