---
title: "How do you exit Play mode in Unity?"
description: "Click Play again or press Ctrl+P (Cmd+P on Mac). From code, set EditorApplication.isPlaying to false in the editor and call Application.Quit in builds."
url: "https://bugsee.com/answers/unity/how-to-exit-play-mode-unity/"
---

# How do you exit Play mode in Unity?

Click the Play button again, or press Ctrl+P (Cmd+P on Mac). From code, use `EditorApplication.isPlaying = false` in the editor and `Application.Quit()` in a build.

```csharp
using UnityEngine;

public class QuitOnKey : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
#if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
#else
            Application.Quit();
#endif
        }
    }
}
```

- `Application.Quit()` does nothing in the editor, which is why the `#if UNITY_EDITOR` branch is needed.
- Changes made to objects while in Play mode are discarded when you exit. To keep them, use the component's context menu: Copy Component, then Paste Component Values after stopping.
- Enable Edit > Preferences > Colors to tint the editor in Play mode so you notice when you are still playing.

## Related questions

- [How do you add a script to a GameObject in Unity?](https://bugsee.com/answers/unity/unity-add-script-to-gameobject/)
