ddrossi93
ddrossi93

Reputation: 385

How to move to next scene using scene manager in Unity 5?

I am doing a tutorial that is using unity 4 and they are using this:

Applicaiton.LoadLevel(Appliaction.loadedLevel +1);

in order to move on to the next scene. I am using unity 5, and it is telling me to use scene manager since the previous method is now obsolete.

What is the new code to replace the one above?

Upvotes: 0

Views: 5926

Answers (2)

TAHA
TAHA

Reputation: 1

using UnityEngine;
using UnityEngine.SceneManagement ; 
public class next_level : MonoBehaviour
{
    public void next_levl(){
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex +1 ) ; 
    }
}

Upvotes: 0

sithereal
sithereal

Reputation: 1686

The Scene struct has a buildIndex variable to store the index. Therefore, to load the next scene:

using UnityEngine.SceneManagement;

int currentSceneIndex = SceneManager.GetActiveScene().buildIndex; 
if(currentSceneIndex<SceneManager.sceneCount-1)
{
    SceneManager.LoadScene(currentSceneIndex + 1);
}

Upvotes: 2

Related Questions