How to quit the game?

Hello Everybody,

I am finishing my first game for Android and I want to put an ‘Exit’ button to quit the App and return to the main screen of the phone/tablet. I have not found the way. My ready version is 2017.4.30.

Thank’s for help…

1 Like

Hello @jean_claude, this is an interesting question. I’ve never heard of a mobile app that can close itself; does that really exist? (I suppose an app that deliberately crashes would de facto cause itself to close, but this approach is not recommended lol :-D)

2 Likes

Hello @auntiel,

Thank’s for reply.

For example, in this game ‘Pro des Mots’

when you press the return button, the app ask you if you want to quit

You can press Yes and the app is closed and the phone/tablet display the main screen.

I just want to close my app in the same way…

:smiley: :smiley:

2 Likes

Hello @jean_claude, thanks for taking the time to give an example with screenshots - I learned something new!

As for your request, Ready games execute inside the Ready app, so for a Ready game to offer the option to return to the device home screen, Ready would need to implement closing itself and provide support for that to the games. I’m not aware of anything like that but perhaps someone else knows about it, and if it doesn’t exist, you can add it to the Suggestion Box :slight_smile:
@Ready

2 Likes

Hi guys! Yes, that’s right, in this case you cannot close the application using the buttons programmed through events. You can only stop the scene itself using the already implemented functionality.

2 Likes

Hello,
Do you think there is a solution when the project is imported to Unity ?

3 Likes

Do you think there is a solution when the project is imported to Unity ?

Our resident Unity expert might be able to help with that :slight_smile:
@Dravins

2 Likes

Hi @jean_claude!

This is actually very very simple. When you are on unity go ahead and make a script called “ExitGame” or whatever you want to call it.

You will see a void Start() and a void Update()

Go ahead and remove void Update() because you won’t need to exit the game every frame :sweat_smile: you can also delete void Start().

Make this in the script instead:

public void ExitTheGame() {

}

In void ExitTheGame() write this:

Application.Quit();

When you do that, save the script and allow it to complete. Go to the button in your scene and make sure it has a Button component. If it doesn’t you can attach one by pressing “Add Component” on the button in your scene and searching for “Button”. In the button component there will be a + sign. Go ahead and press that and drag the script you attached onto your button into that component.

There will be a drop down menu in the button component. Press that and press the ExitScript selection and click on ExitTheGame().

This will allow the button to exit the game when pressed.

I currently do not have access to give you photos to help you out, but if you need some- I’ll make sure to get some photos to help you. However, here is something from the Unity manuals that can further explain this process if needed and provides example code if a key is pressed:

https://docs.unity3d.com/ScriptReference/Application.Quit.html

(Also thank you @auntiel. I’d definitely like to be a unity expert one day)

2 Likes

@Dravins you may not consider yourself a Unity expert, but you certainly are an expert at creating tutorials! That’s a very nice, clear description of the end-to-end process for using Application.Quit()! :+1:

2 Likes

That is super nice of you to say! Thank you @auntiel! :slight_smile:

2 Likes

Hello,

I have just seen your reply @Dravins.

Thank’s a lot for explanation to make a an exit button in Unity. It’s seems clear.
I will test that tomorrow and let you know…

Thank’s also to @auntiel for making the suggestion for you to reply as the resident Unity expert :sunglasses: :sunglasses:

3 Likes

Hi everybody,

I made it !!! :sweat_smile: :grinning: :sunglasses:

Not so simple for me, I am just working with ReadyMaker and Unity for 15 days…
Many pitfalls on the way. Thanks to @Dravins and @auntiel to make me progress in it.

  • After exporting to Unity, to see the entire scene, disable the Ready Canvas with covers
  • The script given by @Dravins works fine, but I don’t find the way to make working as a button an image allready in the Ready scene.
  • I create an UI canvas and an UI image with my ‘exitdoor’ sprite attached to it. Thanks to Youtube…
  • Now I was able to apply @Dravins script to it.
  • Take care to use the same parameters in Canvas scaler for the new canvas created, I have used scale with scene size and the résolution of my Android tablet. If not, the button is not at the good size/place.

I have resolved also all the problems to build the APK, find the good Sdk, Jdk etc…
If someone is interrested for more details… I will be there.

PS : I am french, I try to speak/write english as I can :thinking: :thinking:

ByeBye :handshake: :handshake:

3 Likes

I’m glad everything is working now @jean_claude!

Let us know if you encounter anymore issues in the future.

2 Likes

Congratulations on your success, @jean_claude, and thanks for including your notes on how you did it!

Also, not to worry, your English is quite good :smiley:

3 Likes