My OnTriggerEnter2D Won't work.
I'm making a 2d rpg and i'm trying to load up new scenes using a box collider in Unity 5.3, can anyone help?
Script:
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement;
public class LoadNewArea : MonoBehaviour {
public string levelToLoad;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider2D other) {
if (other.gameObject.tag == ("Player")) {
SceneManager.LoadScene (levelToLoad);
}
}
}
Answer by vittu1994 · May 16, 2016 at 05:00 PM
Do a Debug.Log() in the OnTriggerEnter2D function to see if you are actually colliding. If you are colliding then it might be a problem with the scene ur trying to load. It can maybe not be in build settings, misspelled etc.
Also check if both the player and the collider area have 2d boxcolliders and they are set to trigger
Doesn't seem to be colliding. Any advise on what I could do to fix it?
Never$$anonymous$$d, my tag wasn't set to "Player" so it wasn't registering it. Thanks for your help though :)