Search code examples
unity-game-engineunityscript

How can i stop unity from script?


I need to close unity from my scripts. As if I clicked on the stop-button in GUI. Can i do this directly from code, or not? I know, how i can close a scene, but need to close all processes.


Solution

  • Application.Quit(); // Quit the deployed game/App
    

    Or as Chris commented, use below code to quit Unity Editor:

    EditorApplication.Exit(0); 
    

    Or you wish to pause the player:

    EditorApplication.isPaused = true;
    

    Or consider using boolean property:

    EditorApplication.isPlaying = false;
    

    Or you are talking about this? Then try:

    Debug.Break();  //stop running at run-time,
    

    See online documentation here and here.

    Choose whichever that matches your intents.