Hello,
I tried quitting the scene in the FPS course but it doesn’t work. Rick thinks it has to do with Time.timeScale, but putting one in Quit Application doesn’t work.
LoadScene Script;
PlayerHealth Script;
Hello,
I tried quitting the scene in the FPS course but it doesn’t work. Rick thinks it has to do with Time.timeScale, but putting one in Quit Application doesn’t work.
LoadScene Script;
PlayerHealth Script;
Hi,
Where do you test Quit.Application? In the Unity editor? If so, that method will not work there. It works in standalone builds only.
See also:
Like Nina mentions, Application.Quit
when playing in the Unity editor does not work. Here is how it can be achieved, though. The trick is to just stop play mode
#if UNITY_EDITOR
if (Application.isEditor)
{
UnityEditor.EditorApplication.isPlaying = false;
}
#else
Application.Quit();
#endif
I am testing Application.Quit while in play mode in the engine.
Do I type this script into the SceneLoader.cs file to make this happen?
I don’t know. Wherever you use Application.Quit
, you should use the code I provided instead.
It adds a compiler directive so if you are running in the editor, it will execute UnityEditor,EditorApplication.isPlaying = false;
and if you built the application it will execute Application.Quit
You should also be aware that you cannot quit a WebGL game. I usually have code (which I excluded from the above) to check if it is a WebGL application. But I have other code that checks and removes the ‘Quit’ button if it is a WebGL application
Thank you for letting me know that I cannot quit a WebGL game.
No problem. You can check like this
if (Application.platform != RuntimePlatform.WebGLPlayer)
Application.Quit();
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.