- Home /
Button to next scene
I want to have a button that I press to go to the next scene. I am not new to coding I just had some errors with the script. But I can add animations later so dont worry about that. I just need the code for the button so I can add it to my actual physical button. I also want a spot to put audio to play when I click it. PLEASE ANY ANSWER WOULD HELP
Answer by MaT227 · Feb 03, 2014 at 07:23 AM
You can read the Documentation for better explanations but here is some code.
if (GUI.Button(...))
{
Application.LoadLevel ("level_name");
}
Don't forget to include the desired level in the build level list (File->Build Settings...) otherwise it won't work. This is the simplest way to load levels, there are several ways to do this (asynchronously, additively, etc...) I suggest you to look at the documentation.
You need to look at the documentation GUI.Button. Everything is well explain with examples.
You need to put a Rect that defines the position and the size and the text displayed
$$anonymous$$y button has no text or textures displayed. I just want a script that loads the next scene when I left click on the Button itself
Could you post some code ? As you said, you are not new to coding, so you can just drop the line Application.LoadLevel ("level_name");
at the desired place.
pragma strict
function Update () {
if (Input.Get$$anonymous$$eyDown("LeftButton")){
Application.LoadLevel(level2);
}
}
Thats my code but I get this error: Assets/Scripts/PanicButton.js(7,23): BCE0005: $$anonymous$$ identifier: 'level2'.