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.

Using a Unity button to switch between scenes.

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

Written by Loek van den Ouweland on 2017-10-12.
Questions regarding this artice? You can send them to the address below.