- Home /
Load scene on button press
I have a script. I want it to load a scene when I push down a key. In this case the Space bar. However it does not work. I really do not know what is bad with it. I am new to unity scripting and I am pretty sure its just my script. Here is my code:
function Update() {
if(Input.GetButton("Jump")){
Application.LoadLevel (3);
}
}
Any help would be apreciated. :) Thank you.
Answer by MC HALO · Apr 17, 2011 at 05:36 PM
Ok the script looks good to me but what you need to do is go to unity, click on file then build setting. Once you lick on build settings a menu will show up. In that menu there should be a field called "Scenes In Build", in this list you should have nothing. What you need to do is go to you "Project" view window and look for your scene once you find it drop and drop it on to your "Scenes In Build " window. Once you have done that the build view will add it to the list and on the side of the scene you will see a number 0 or 1. what this means is it has numbered the scene so like in your script you said load (3) that means the build will look for the number 3 and load that level.
the second thing is have you add this to your object if you have not it wont work.
and finally don't say:
Application.LoadLevel (3);
because in unity when you build a new scene and add it to the Build it will put this level above each other and it is one big problem.
instead use it like this :
Application.LoadLevel ("Level1");
so instead of putting 1 put you scene name in there
hope this helped :)
In a way you were right it was 2 although even so it did not do anything when I did change it. Also I tried to change it to the name of my scene and it did not work. (Got an error therefore not allowing me to play it...) I can post my ugly smelly old scene online to show you that it will not work. I am willing to try other things f you have other ideas.
And i am willing to help you please send me your project folder at my google mail account which is:
Hummad.Nazir@gmail.com
do not send it trough hotmail because it does nopt allow you to update huge files :) i look forward from hearing from you
So I need help to make it so that when I press a button that I created it goes onto the next scene. How would I do that?
Answer by Uzquiano · Apr 17, 2011 at 05:35 PM
Hi,
Did you check the list of levels in the game? Use File->Build Settings
I mean, is there any level number 3?
Anyway, check the documentation if you didn't...
Answer by Guardian2300 · Jul 10, 2013 at 07:42 PM
Hello, Basically you write Application.LoadLevel("SceneNameDesired"); Then you have to go into Build Settings and drag the scene into the box with your current scene, should have two scenes after in build settings. Then it should work
Your answer
Follow this Question
Related Questions
Input.GetMouseButton on multiple objects 1 Answer
Load / Stream 3rd Party Scene? 1 Answer
unity3D changingscene 0 Answers
Scene not loading properly everytime 3 Answers
Load Custom Scene 2 Answers