<aside> 📄 This script exits the game build when the escape key is pressed.

</aside>

using UnityEngine;

public class ExitGameOnEscape : MonoBehaviour
{
    void Update()
    {
        // Check if the Escape key is pressed
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            // Exit the game
            Application.Quit();
            // Note: Application.Quit() will only work in standalone builds. It won't work in the Unity Editor.
        }
    }
}