Attach script to GUI Button

I wrote a simple script. I need to know three things!

  1. How to attach a script to a GUI Button?
  2. How to make a button call a specific function within the script?
  3. What command to use to quit the application and return to Windows (or MacOS if you’re using a Macintosh)?Here is the script I wrote!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class NewBehaviourScript : MonoBehaviour {

// Use this for initialization
void Start () {
}

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

// Button 1 click, the start button
void StartGame() {
SceneManager.LoadScene(“Scene One”);
}

// Button 2 click, the quit button
void QuitGame() {
SceneManager.UnloadScene(“Scene Title”);
}

}

Jump ahead to around minute 9 to learn about how to hook buttons up to scripts in the scene. UI Components - Unity Learn

You can quit from unity with Application.Quit() (Unity - Scripting API: Application.Quit)

Thanks kru

In addition, check out my tutorial on Unity Event. It’s really fundamental to how I do everything in Unity nowadays (not just UI).