Prevent Quit (Windows)

Is there a way to respond to (and perhaps cancel) a quit event when the user clicks the X button in the top right corner of a Unity-generated window? I want to ask “Are you sure you want to quit?” in order to prevent users from accidentally killing the game while clicking around.

Thanks for your time!

Just look for Application.CancelQuit and MonoBehaviour.OnApplicationQuit. Note: This will only work in standalone apps. iPhone or Webplayer just ignore this (at least CancelQuit).

First you would need pro to call native OS code 1. After that it would look somthing like this:

Application.Exit( );

if (MessageBox.Show("Really Quit?", "Exit", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
Application.Exit();
}