Hi,
I need help urgently as i am new in unity3d.
i have 3 scenes, each scene has a left and right button.
I wanted this: If i am in scene1,and i press the right arrow button, it should do a Application.LoadLevel to scene 2. and if i press left arrow, i move back to previous scene.
But the strange thing is that, now with three scene setup and i go to scene 1 and when i press the right arrow, it moves me from Scene1 to scene2 to scene 3, without stopping at scene2. the left arrow bring me directly to scene 1 without stopping at scene2.
i tried forcing the variables KeypressedFw and KeypressedBck to false but seems does't work. please help.
here is the js for scene1, that i attached to my Main Camera.
function OnGUI() {
var keyPressedFw; var keyPressedBck;
keyPressedFw = false; keyPressedBck= false;
keyPressedFw = (Event.current.keyCode == KeyCode.RightArrow)? true : false; keyPressedBck= (Event.current.keyCode == KeyCode.LeftArrow)? true : false;
GUI.Button(Rect((Screen.width / 2) - 75, (Screen.height / 2) -50, 150, 100), "Scene 1"); GUI.Button(Rect((Screen.width / 2) - 150, (Screen.height / 2) -50, 50, 100), "Bck"); GUI.Button(Rect((Screen.width / 2) + 100, (Screen.height / 2) -50, 50, 100), "Fwds");
if (keyPressedBck == true) {
}
if (keyPressedFw == true) {
// yield WaitForSeconds(.5);
Application.LoadLevel ("scene2");
}
} //onGui
Peviously i was using The following code that allows me to even use the mouse to change scenes:
function OnGUI() {
var keyPressedFw = (Event.current.keyCode == KeyCode.RightArrow)? true : false; var keyPressedBck= (Event.current.keyCode == KeyCode.LeftArrow)? true : false;
GUI.Button(Rect((Screen.width / 2) - 75, (Screen.height / 2) -50, 150, 100), "Scene 1");
if (keyPressedBck || GUI.Button(Rect((Screen.width / 2) - 150, (Screen.height / 2) -50, 50, 100), "Bck")) { } if (keyPressedFw || GUI.Button(Rect((Screen.width / 2) + 100, (Screen.height / 2) -50, 50, 100), "Fwds")) { // yield WaitForSeconds(.5); Application.LoadLevel ("scene2"); } }
please somebody help.
regards nigel
Being new to Unity doesn't make your problems any more urgent - it just means you are likely to have more of them. What's with the empty ifs? I don't see anything about loading scene 3 anywhere in this code. Assuming only the yield is commented out in the second code, the only change is moving the buttons out of the if statements. Is this what you meant to post?
– anon16733337