This is quite an interesting topic Russell. The answer will really depend on the platform you plan to build/publish for.
If you were going to build for PC/Mac, then yes, you could add an option to quit the game and use the appropriate code to do so (Application.Quit
).
Of course, this would then need a different behaviour when it’s running in the Unity editor, you could use something like this;
public void Quit()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit(); // or include more platform specific functionality
#endif
}
Additionally, if/when the game is run in a browser you will not have control over the browser itself, so the same method of quitting the game won’t work. What you could do in this scenario would be to perhaps either not show the Quit option, or, if you do, have the browser redirect to another web page. Some people have opted for just redirecting to a blank page, I don’t personally see the value in that, however you could redirect to your own website, a portfolio page of other games you’ve made, a link to the store where you game could be found, or perhaps a feedback survey to ask for feedback on your game to collate some valuable feedback.
Finally, different vendors have their own requirements to consider, for example, Apple do not want developers to provide functionality to quit the applications, in favour of their own software managing it.
I hope the above is of use
See also;