- Home /
Script Not Working?
I added this script to my character:
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if (hit.collider.name == "Exit_Flag")
{
Application.LoadLevel(Application.currentLevel + 1);
}
}
so when i hit a flag i made named Exit_Flag it would go to the next level because Statement was nice enough to make it for me.
When i try to test the game i get this error:
Assets/Change Level.js(5,43): BCE0019: 'currentLevel' is not a member of 'UnityEngine.Application'.
Anyone know a fix?
It's better you keep follow ups as comments in the main question/answers as it would become much easier finding responses. The link to the answer is http://answers.unity3d.com/questions/36182/how-do-i-exit-level/36183#36183 and the code has been corrected.
Answer by FLASHDENMARK · Jan 12, 2011 at 05:44 PM
I dont know if you can type it the way you did (Application.currentLevel +1), mabye. Try typing the name of your scene instead. if your next level is called MenuScene, then type:
if(some event has happend) { Application.LoadLevel(MenuScene); }
or
if(some event has happend) { Application.LoadLevel("MenuScene"); }
It works as long as your levels are in linear order, such that level 2 comes after level 1.
Answer by Statement · Jan 12, 2011 at 05:46 PM
Application.currentLevel should be Application.loadedLevel.
Sorry for the mistake!