- Home /
Application changes???
Question:
public void LoadLevel(int lvlnum) { Application.LoadLevel(lvlnum); } This is the function I am calling to load the level however unity is saying: " Application.LoadLevel is obsolete: Use SceneManager.LoadScene
What does unity mean by this?? Where exactly do I add that code if that is the case?
Answer by FLASHDENMARK · Jul 26, 2016 at 08:28 AM
Unity now requires you to do things a bit differently.
As Unity tells you, you'll have to use the SceneManager.LoadScene instead of Application.LoadLevel. This is done like this:
// Include the SceneManagement class
using UnityEngine.SceneManagement;
public void LoadLevel (int lvlnum)
{
SceneManager.LoadScene(lvlnum);
}
If you want to avoid the using directive then you can also do it like this:
public void LoadLevel (int lvlnum)
{
UnityEngine.SceneManagement.SceneManager.LoadScene(lvlnum);
}
There are plenty of available information about this and a Google search would properly have helped you as well.
question though what about loading the current level? Say I ended the game and it said press R to restart. How what code would I use to load the current level? I have the key set up. Using the "LoadedLevel" code is obsolete
Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().buildIndex);
The code I have so far is:
UnityEngine.Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene()
However within LoadScene parenthesis it won't load the code you stated.