Why I cannot close program through close button?

public class Exit : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }

    void OnGUI () {
        if(GUI.Button(new Rect(Screen.width-55,Screen.height-40,50,30),"Exit")){
            Application.Quit();
        }
    }
}

I create an exit button to quit game. The button show on the screen, but the button doesn’t work when I click it.

Are you trying this from the Editor, or in a built exe? Application.Quit() doesn’t do anything in editor.

Could you be specific about where/how you’re testing the button? It only works in a built application, but not if you’re testing in the editor or on an application that is being accessed by the web player.

So, if it’s not working in the editor then build and run the application and then try it, it should work perfectly :slight_smile:

The game buttons will work only when you build your game so it will not work in the editor if you finished your game you can click build and run