How to EXIT GAME with BUTTON in Unity

preview_player
Показать описание
In this Video we see the instruction we need to execute in order to close a Unity game.
We're gonna setup a simple scene with a button to test this function.
By default we can quit the game in Unity using Alt+F4, but in this case we want to close the game programmatically.

Instruction to close a Unity game:

Application.Quit();

How to exit the game with a button in Unity:

1. Create a Button in the Canvas
2. Create a Script to exit the game or use an existing one, define inside a public function for the button to execute it (example below).
3. Create an OnClick Event in the Button component, assign the GameObject who has the Script where the Exit function is defined and select that function from the list.

Example function to exit the game:

public void ExitGame(){
Application.Quit();
}

____________________________________________________________
*LINKS*

____________________________________________________________

#EN
Рекомендации по теме
Комментарии
Автор

For those wondering why the button is not closing the game inside the Unity Editor, it is because it only closes the game on the build (executable game).

leonamferreira
Автор

How does this only 43 views like, all of the other popular "How to make a quit button" videos didn't work and this one did
thumbs up from me!

portallicious
Автор

Very Informative Tutorial!!. Thank you :)

ahmedshah
Автор

I am new to unity but you saved my so many hours with this two minutes video. Thanks a lot!!!

dumbkhan
Автор

for those saying it doesn't work, it might be that you're testing it in the editor view, it wont work when you're in the editor view. you have to build and run the game. he does this at 0:28

mas_aco
Автор

Thank you much. Don't miss the part where he drags the Control script into the Main Camera settings area. As I did....

rodmanunderhilliii
Автор

thank you ive been to so many totorials that didnt work but this is the one that did thank you very much

Wabbaxt
Автор

thank you so much, without you i can't do this
+1 Sub

MomazosDiego
Автор

That was soooo helpful !! youre my savior...

yereenday
Автор

How can i make the game quit when i press on esc? I have tried watching many tutorials but it doesn't work. pls help :')

cottonsocks
Автор

I just came here for the application.quit command

davidbielsa
Автор

Doesn't work for me. I click on the button but nothing happens

xornedge
Автор

nope scam it did not work i was not even allowed to put the name exit() for it scam

RocksYum
Автор

increase the font size.. cound see shit

sed