Make a button quit the game, Unity 4.6 UI C#

Hello, i would like some help with some code that could make it so that when the use presses a button on the screen,the exit button on my main menu, the game exits. I know that the Application.Quit() will allow me to exit, but how to i make it so that when a unity ui button is pressed, the game exits. Thank you

Create your script with a public function e.g. ClickExit() and put you Application.Quit() in there, also anything you need to do before quiting like save player data.

Put that script on your button and the select the button. Look in the inspector for the OnClick and click +

Then drag your button onto the slot that appears. After that you should be able to select your ScriptName - > ClickExit from the drop down to the right.