UnityEngine.Application.LoadLevel(String) is obsolet!
When trying to work my main menu for one of my creations, I was repeatedly getting this error/warning, that did although lead into a larger problem. I do not understand what I am doing wrong... If anyone can help, it would be greatly appreciated... The error occurs on line 10 below
function OnGUI(){
if(menu){
GUI.Box(new Rect(Screen.width /2 -100,Screen.height /2 -120,200,160), "Game Over");
if(GUI.Button(new Rect(Screen.width /2 -80,Screen.height /2 -80,160,40), "Retry")) {
LoadData();
}
if(GUI.Button(new Rect(Screen.width /2 -80,Screen.height /2 -20,160,40), "Quit Game")) {
mainCam = GameObject.FindWithTag ("MainCamera").transform;
Destroy(mainCam.gameObject); //Destroy Main Camera
Application.LoadLevel ("Title");
//Application.Quit();
}
}
}
Answer by tanoshimi · Feb 04, 2017 at 08:31 AM
The problem is that the LoadLevel method is obsolete. i.e. your code is out-of-date and will stop working in a future version of Unity as it relies on features that are being removed.
The correct updated approach is to use the SceneManager:
https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html
Your answer
Follow this Question
Related Questions
Pause menu Change 0 Answers
Writing dropdown selections to file 1 Answer
UnityEditor GenericMenu - Problem with 'AddItem' in Foreach Loop 1 Answer
How to use this menu (skins) in my game? 0 Answers
Responsive UI 0 Answers