how to change scene unity code example

Example 1: how to switch scenes unity

SceneManager.LoadScene("MyScene");

Example 2: change scene unity

SceneManager.LoadScene("name of scene", LoadSceneMode.Single);

Example 3: how do you switch scenes unity

using UnityEngine.SceneManagement;

SceneManager.LoadScene('Scene');

Example 4: load scene unity

using UnityEngine.SceneManagement


public class LoadScene : MonoBehavior
{
	public string sceneToLoad = "Level2";
    
    public void Start()
    {
    	SceneManager.LoadScene(sceneToLoad);
    }
}

Example 5: loadscene unity

using UnityEngine;
using UnityEngine.SceneManagement;

public class Singleplayer : MonoBehaviour
{
    public void LoadNextLevel()
    {
    	//This will load the next scene in the buildIndex, e.g if in scene 3, go to scene 4
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex +1);
    }
}

Example 6: change scene unity

SceneManager.LoadScene (sceneBuildIndex:/*Put the number here*/);