- Home /
change scene with keypress??
hey guys, im after a basic javascript that allows me to return back to the main menu scene when i press Escape in my game, please help :)
thanks
Comment
if(Input.GetButtonDown("menu_button")) Application.LoadLevel("$$anonymous$$ain$$anonymous$$enuScene");
if (Input.Get$$anonymous$$ey($$anonymous$$eycode.Escape))
Application.LoadLevel("LEVEL NA$$anonymous$$E");
It will also work in mobile devices. When the player will touch the back button
Answer by Vardan Meliksetyan · Feb 11, 2014 at 06:10 PM
Hi, change code like this
function Update() {
if( Input.GetButtonDown( KeyCode.Escape) ) {
Application.LoadLevel(0); // it number or name, string
}
}
https://docs.unity3d.com/Documentation/ScriptReference/KeyCode.html
https://docs.unity3d.com/Documentation/ScriptReference/Input.html http://docs.unity3d.com/Documentation/ScriptReference/Application.LoadLevel.html