Unity Scene Manager

Przełączanie scen / poziomów w Unity

public class MySceneManager : MonoBehaviour
{
    int activeSceneNumber;
    int scenesTotal;
    void Start()
    {
        activeSceneNumber = SceneManager.GetActiveScene().buildIndex;
        scenesTotal = SceneManager.sceneCountInBuildSettings;
    }

    
    void Update()
    {
        if(Input.GetMouseButtonDown(1))
        {
            SwitchScene();
        }
    }


    void SwitchScene()
    {
        if(activeSceneNumber + 1 < scenesTotal)
        {
            SceneManager.LoadScene(++activeSceneNumber);
        }
        else
        {
            SceneManager.LoadScene(0);
        }
    }
}
Scroll to Top