Switch Between Scenes in unity

In every game you need to switch between scenes so let’s explain how we do that in unity.

  • Firstly you must to have two or more scenes in your assets.

  • In that example we have scene 01 and scene 02

  • Create a new script name it SceneLoader and drag it to button.

  • Copy and past that code in SceneLoader script
using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneLoader : MonoBehaviour {

public void LoadScene(string level)
{
SceneManager.LoadScene(level);
}

public void RestartScene()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}

public void NextScene()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
  • in on Click select SceneLoader > LaodScene

  • Click on the button and put the name of scene where you want switch

  • Go to scene 02 and  click on the button and put the name of scene where you want Back

I Hope that Help you 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *