- Home /
Next Level Script Wont Work
Hi guys i have a script attached to my player so when it collides with a certain object which is a trigger it loads the next level. i have written a script but it wont work. I am using the 2d unity 3d because i am making a 2d game.
The Script
using UnityEngine; using System.Collections; public class NextLevel : MonoBehaviour {
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
void OnTrigger2DEnter(Collider collision){
if (collision.gameObject.tag == "Finish") {
Application.LoadLevel("2");
}
}
}
Comment
Is the level named '2' or is it numbered 2? You are loading the level named '2'.
No the next scene is called "2" also i have gone into the build setting and made the normal level 0 and the next level 1 http://gyazo.com/f2916605a3755936a85c00023da57e3c
Have you put in a Debug.Log Statement to see if that collision, with that tag, actually occurs?
Best Answer
Answer by Flint Silver · Mar 03, 2014 at 05:26 PM
the code is wrong! if you are using 2D collider you will use onTriggerEnter2D and Collider2D:
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Finish")
{
Application.LoadLevel("2");
}
}