- Home /
Aplication.LoadLevel isn't working in built version
Hi guys!
I encountered this problem only yesterday, before that everything worked fine, and I didn't change anything. But this is not new with Unity, now is it? :D Anyway, so I have my main menu screen with the play button as a empty, with collider, and a Text mesh. What is happening when I click on the play button in the built version, is that the whole game crashes. However in the editor, everything works just fine... I hope you can help me, because I see nothing wrong. Also just an info, I have the scenes in the build editor and they are all checked. I tried the script with an int too instead of a string, same result. On to the script:
var levelToLoad : String;
var soundhover : AudioClip;
var beep : AudioClip;
var QuitButton : boolean = false;
function OnMouseEnter()
{
audio.PlayOneShot(soundhover);
}
function OnMouseUp()
{
audio.PlayOneShot(beep);
//yield WaitForSeconds(0.35);
if(QuitButton)
{
Application.Quit();
}else
{
Application.LoadLevel(levelToLoad);
}
}
@script RequireComponent(AudioSource)
$$anonymous$$aybe I wasn't clear enough. I know that my scene has a number, and they are added in the Scenes to build window. (I want to load the 2nd scene btw). And I set the string in the inspector, so the script is reusable. I tried it with string and number too, both loads in the editor just fine, but not in the built version.
first of all don't post comments as answers.
second of all did you read my answer?
and because you have made an answer I have down voted your answer
Sorry, for being rude, didn't read through your answer carefully enough :) But it still isn't working :(
hmmm, ... I'm out of ideas, as it worked for me, ...
can you update your code how are you trying to solve it?
and after changing the code did you build it again?
Here is the code I'm using now: var levelToLoad : String = "HospitalScene01"; var soundhover : AudioClip; var beep : AudioClip; var QuitButton : boolean = false;
function On$$anonymous$$ouseEnter()
{
audio.PlayOneShot(soundhover);
}
function On$$anonymous$$ouseUp()
{
audio.PlayOneShot(beep);
//yield WaitForSeconds(0.35);
if(QuitButton)
{
Application.Quit();
}else
{
Application.LoadLevel(levelToLoad);
}
}
@script RequireComponent(AudioSource)
I did rebuild it, but it still wasn't working :/ Also here is the crashreport I get, in case it helps anything: http://pastebin.com/6qSTkn6Y
Okay, I have no f*cking idea why, but it is working now. I just deleted the scene from the build window and readded it...unity...
Answer by Zentiu · Feb 22, 2014 at 12:14 PM
1) Check if the scene you want to load is in your BuildSettings under "Scenes in Build".
2) use the code Application.LoadLevel ("nameOfTheSceneIWantToLoad");
or
Application.LoadLevel (1);
the scenes you put in the buildsettings start from 0 counting up so your main menu might be 0 and your first level might be 1, next level 2, third level 3 ect.
3) don't know about javascript but in c# I don't need to make a variable for it.
Application.LoadLevel (1); // you just made variable here. int 1
if you want to use no variable you do:
int variableLevel;
Application.LoadLevel (variableLevel);
but afaik in C# you get error as you didn't set the variable before use.
I have it in c# and I haven't put a variable in and it works just fine. all ya need to do in c# is write the name of the screen you wish to load as a string in the LoadLevel brackets and you're good to go.
Application.LoadLevel (1);
//or as a string
Application.LoadLevel("myNewScene");
ohw wait, you're right if you don't have either a variable or the stringname in those brackets.
don't $$anonymous$$d me.. just a little tired :/