I’ve finished the tutorial for the text-based adventure game. Thanks for the addition of the for loops. My code doesn’t currently seem to have the “q” for quite functionality implemented. I’m not sure why. I couldn’t easily see which video we implemented that in. Could you please direct me to it?
Hi, welcome to the community
A few people have raised this, I’m not sure if @Rick_Davidson is aware.
With regards to the quit functionality, you may need to give some consideration to the platform the game will be played on. If you were to build for a Windows/Mac application then you could use;
Application.Quit();
Note, the above is ignored by the Unity editor.
However, Apple, for example, have some specific rules with regards to the closing of applications, and as for a WebGL build, you won’t have access to the process running the Web Browser, so you can’t close the application there anyway.
There are some work arounds, they have already been posted on the forum, but to give you some info;
-
You can use
Application.platform
to determine which platform the game is currently running on. -
You could redirect the player to another URL when they choose to quit your game, such as a feedback form, a portfolio of your other games or perhaps your own website.
-
You could remove the Quit button if your game is for a platform which doesn’t really need/support it.
-
You can use preprocessor directives to partition parts of your code to run only on specific platforms, a handy use of this is when your game is running into the Unity editor, for example;
private void Quit() { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif }
If you were creating a WebGL build you could also call JavaScript functions from Unity, so potentially, and I’ve not tried/tested it, but you could call a JavaScript function to close the browser window. At best I suspect this would lead to a dialog window appearing stating that the web page was trying to close, do you want it to etc. Most users will be familiar with the little close button in the corner of the browser window, so personally, I wouldn’t invest a whole lot of time on that, but nor would I display a Quit button if it doesn’t do anything
Hope the above is of use
See also;
- Unity - Scripting API: Application.Quit
- Unity - Scripting API : Application.platform
- Unity - Scripting API : RuntimePlatform
- Unity - Manual : Platform dependent compilation
- Apple - Technical Q&A : How do I programmatically quit my iOS app
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.