- Home /
Changing scenes by pressing a key?
Okay so this is probably one of the easiest things to do but somehow I'm having problems. Basically I have a scene with just a camera and a GUI Texture that explains the game's controls. I want the player to press "Space" to continue to the game. Here's the script:
if(Input.GetKeyDown(KeyCode.Space)){
Application.LoadLevel("Level1");
}
Yes, Level1 is in the Build Settings. I've attached it to the camera with no luck, the GUI Texture, and even created an empty. I can't get it to work no matter what. I'm sort of new to this so I apologize in advance for the stupidity haha. Any help is appreciated. Thanks!
This piece of code works well. The problem is in other place.
Is this code placed in Update() or FixedUpdate() function?
Is the scene file name exactly "Level1.unity"?
Answer by Dogg · Aug 18, 2014 at 07:10 AM
Just as "JustFun" said. The code needs to be in the Update function, and make sure the scene is named Level1. It works perfectly fine with me. Here's how I implemented your code:
void Update(){
if (Input.GetKeyDown (KeyCode.Space)) {
Application.LoadLevel ("Level1");
}
}
I have it on my menu script on the Main Camera. Try it out.
Thanks alot! Also thank you JustFun. I can't believe thats all I had to do...haha.
Your answer
Follow this Question
Related Questions
Teleporter 2 Answers
Load scene on button press 4 Answers
Application.LoadLevel Strange Problem 2 Answers
Can a script be loaded to a next scene? 3 Answers