Hello I really need help. How do I create a exit/Quit button for my game? I want to attach it to a normal button, meaning that I have my own image but I just cant seem to find anything!
Thanks
Hello I really need help. How do I create a exit/Quit button for my game? I want to attach it to a normal button, meaning that I have my own image but I just cant seem to find anything!
Thanks
If the button already exists, you’re almost there! All that’s left is to create a method in a script that looks like this:
void doExitGame() {
Application.Quit();
}
and then add it to the “On Click ()” section of the Button object.
You can do this: first go to gameobject: UI, then create a Canvas.then go to ui again and create button. Position it to your liking, Then create a c# script and call it
“Quit script” or something, and in it, under the update void, enter this.enter code here
void QuitGame () {
Application.Quit ();
Debug.Log("Game is exiting");
//Just to make sure its working
}
I think this will help
//Javascript
function OnGUI () {
// another code above...
var quitGame: boolean = GUI.Button(Rect(Screen.width/2 - 100, Screen.height - 200, 200, 20), "Quit Game");
if(quitGame) {
Application.Quit(); // As far as I know, this only works in the compiled game (.exe)
}
}
//C#
void OnGUI () {
// another code above...
bool quitGame = GUI.Button(new Rect(Screen.width/2 - 100, Screen.height - 200, 200, 20), "Quit Game");
if(quitGame) {
Application.Quit(); // As far as I know, this only works in the compiled game (.exe)
}
}