Load/Change scene with UI Button

Ok this has been really getting uo my nose for a couple of days. trying to change to game scene from a main menu, using

 Application.LoadLevel(sceneToChangeTo); 

but I get an error saying that that line is obsolete and to use

 SceneManager.LoadScene

but When I use that line it then tells me that it can’t be used in that context. some please help and elaborate a little more because I can’t find anything else that is current or useful to what I am trying to achieve.
PLEASE HELP BEFORE MY COMPUTER GETS THROWN OUT THE WINDOW, haha it’s been driving me mad especially since I realize it’s probably going to be really simple solution.
Cheers

1 Answer

1

Hello,

Yes you are correct. Application.LoadLevel became obsolete and was replaced by the new SceneManager.

To use it, simply add using UnityEngine.SceneManagement;to the top of your C# file (or import Unity.SceneManagementfor Javascript).

You now have access to the SceneManager and can load scenes with the line: SceneManager.LoadScene(scene).

You can pass in the scene name as a string or the scene index as an integer.

For more information on the SceneManager.LoadScene refer to the docs.

Hope this helps!