Load next level problem

Hello !
while developing the Garden Glitch game .I want to add.
like If a player wins the level 1 then I want to load the ** Congratulation** scene.
and When the Congratulation scene is loaded and if player press the Ready button in that scene then load the Level 2
and similarly if a player wins Level 2 then again load the ** Congratulation** scene.
When the Congratulation scene is loaded and if player press the Ready button in that scene then only load the Level 3 and so on .

So in my case I am able to load the ** Congratulation** scene but I cant load the next level dynamically (eg. level 2 , level 3).

    public void LoadNextLevel()
    {
        
        Time.timeScale = 1;
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
       
    }


I think only this code cannot work
Please somebody help me

Hi @Subit_Dhakal,

You could use the DontDestroyOnLoad.
https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

Store the current scene index as an int in an object that won’t get destroyed. This way it will carry across to the ‘congratulation scene’. Then when the player presses the ready button you can then read the int value stored and use that to determine which scene index you need to now load.

Cheers,
Todd

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms