Using a Unity button to switch between scenes

Unity allows to create multiple scenes but how do you switch between them with a script? In this tutorial you will learn how to create two scenes and switch between them by clicking a button

goto scene

Create two scenes

Your Project window should look like this:

project view

Change script to open scenes

Your code should look like this:

using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneSwitcher : MonoBehaviour
{
    public void GotoMainScene()
    {
        SceneManager.LoadScene("main");
    }

    public void GotoMenuScene()
    {
        SceneManager.LoadScene("menu");
    }
}

Create buttons to trigger the script

Repeat creating a button to go to menu scene