- Home /
Load level on button press not working - new scene loads instantly without pressing key
Hi! Sorry for the newbie question - I've looked around but I just can't work out why this is happening:
I've attached the below script to a game object in my title scene, and want the main scene to load if either of the 4 arrow keys are pressed.
But as soon as I open the title scene, the main scene loads immediately after, without any keys being pressed!
If anyone can help - it will be so much appreciated!!
function Update () {
if ((Input.GetKeyDown(KeyCode.UpArrow) == true));
else if ((Input.GetKeyDown(KeyCode.DownArrow) == true));
else if ((Input.GetKeyDown(KeyCode.LeftArrow) == true));
else if ((Input.GetKeyDown(KeyCode.RightArrow) == true));
Application.LoadLevel (1);
}
Laurien
Answer by mwbranna · Oct 20, 2014 at 10:11 PM
Your "if" statements have no bodies, so regardless of the condition they will continue to the rest of the function.
Try
if (Input.GetKeyDown(KeyCode.UpArrow) ||
Input.GetKeyDown(KeyCode.DownArrow) ||
Input.GetKeyDown(KeyCode.LeftArrow) ||
Input.GetKeyDown(KeyCode.RightArrow)) {
Application.LoadLevel(1);
}
Thank you so much!!! It works :) I'll read into your explanation now!
Your answer
![](https://koobas.hobune.stream/wayback/20220613165532im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Function deleting string by itself. 0 Answers
OnGUI: += and -= operations problem 2 Answers
LoadSceneMode.Single seems to be not working. 0 Answers
Loading scene in background? 1 Answer
Loading Screen? 6 Answers