1
votes

I am new to unity and I am still learning. I am making a game and its going great but I have a problem with a Quit button.

It doesn't use the script attached to the On Click () section in the button menu.

There's an EventSystem in the Hierarchy, the Force Module Active is checked, the button is a child to a canvas. I don't know why the button isn't working

Here is the code in the script attached to On Click ()

public void Quit()

{
    Debug.Log ("YES IT WORKS");
    Application.Quit ();
}

I want the program to close when the button is pressed but when the button is pressed nothing happens!

3
I'm not sure if enough code has been posted to be useful. minimal reproducible example - Micky
That's all the code that the script has. Here is the On Click part imgur.com/a/UCj1fhy - Boris Nacev
Does the Debug.Log() work? If I'm not mistaken Application.Quit() doesn't work in development, only in the standalone build. - Savaria
No the Debug.Log() doesn't work. - Boris Nacev
Post some screenshot of QuitButton's inspector helps people to solve your problem - siusiulala

3 Answers

1
votes

The function is not being called when the button is pressed which means that you have not selected the function in the onClick settings. To do this, ensure that the script is attached to the button and then dragged into the onClick box of the button in the inspector. Next, click on the dropdown and hover over the name of the attached script and select the function that you want to call.

0
votes

Solution

Instead of using Application.Quit() try to shift the your working scene to the home screen .Your every game should start and end at the same level which is also known as the main scene of the the game. Secondly before shifting to other scene you should destroy your player and save the scores in the player pref .

Player Pref:

The library which helps the user to store the data and show them on the main screen , Hence the use of database will not be there in order to save the data for the small games . You are beginner so you should look at these all thing on You tube or the unity website documentation available on its website

0
votes

Are you in the Editor? Application.Quit() only works when you build the application (for PC and Android. It should not work on iOS, and even if it works it should display as a crash so it's not good).