UnityEngine.Application.LoadLevel is obsolete Use SceneManager.LoadScene

add
using UnityEngine.SceneManagement;

to the top of your script than use SceneManager.LoadScene(string scenePath)

In JaveScript

Add
import Unity.SceneManagement

After that you can replace Application.LoadLevel() with SceneManager.LoadScene()

 

change:
UnityEngine.SceneManagement.SceneManager.LoadScene(“Application.loadedLevel”);
to:
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
or
SceneManager.LoadScene(“Continue”);

 


SceneManagement instead of Application

Where previously we would use Application.LoadLevel to load a new level. In Unity 5 we now need to use SceneManager.LoadScene. Some of the names and usages are different so please take a look at the SceneManager documentation.

For example:

// At the top of your script
using UnityEngine.SceneManagement;

// Load next scene from build settings
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);

// Load new scene by name
SceneManager.LoadScene(“SceneName”);

OnLevelWasLoaded() in Unity 5.x

OnLevelWasLoaded() is deprecated as of Unity 5. Even though it might still work, we recommend to use the SceneManager. For further information on this, please see SceneManager.sceneLoaded in the API. If you do not know about delegates yet, do not worry. Simply use the code below:

// at the top of your script
using UnityEngine.SceneManagement;

private void OnEnable() {
SceneManager.sceneLoaded += OnSceneLoaded; // subscribe
}

private void OnDisable() {
SceneManager.sceneLoaded -= OnSceneLoaded; //unsubscribe
}

// The replacement for the OnLevelWasLoaded method. You may name it as you want. Make sure to subscribe/unsubscribe the correct method name (see above)
private void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode) {
// your code
}

Shares
|ShareTweet

Post Author: Golden Ninja Studios