- Home /
How to: Press (A) to restart, (B) to quit (GamePad)
I did research but can't find what I need, and it seems simple maybe? At the end of my game I want to be able to have the player either press A to restart the game, or B to quit application. (On the GamePad) I have an ending scene and will have some text that tells them this also. I don't need any Hover script. Just something like: (This is sample code) I have no idea what function I would actually need to use and if this is even close to being right.) Anyone have any ideas or can direct to me to a post they know of?
function Update () {
if (Input.GetButton("joystick button 0"); LoadLevel(0);
if (Input.GetButton("joystick button 1"); QuitApplication;
}
Answer by theLucre · Dec 07, 2014 at 08:19 PM
Couple things:
Your if statements need parenthesis, not semicolons
In Edit > Project Settings > Input you define the joystick keyboards and name them with a string, typically Fire1 and Fire2 are the defaults. Use that for a GetButton check.
Application is the base class for changing scenes or quitting the game. See http://docs.unity3d.com/ScriptReference/Application.html for more info.
function Update () { if (Input.GetButton("Fire1")) Application.LoadLevel("YourSceneName"); if (Input.GetButton("Fire2")) Application.Quit(); }
Thanks for the help. Like I said my code was a total sample and I just kinda made it up with what I thought was close, I was pretty close though! :P I did try this and am still getting errors about the input. Says its still not set up and I did exactly what you said. $$anonymous$$aybe its because I'm not using the character controller that comes with unity. I am using the OVR one that is with the oculus rift plugin... I'm just going to skip doing the restart and quit for now. Its not that important.