Loading scenes in Unity
Switching and loading scenes in Unity using their built-in functions is very simple.
In a function, use “LoadScene(Scene Name);”:
Or alternatively, use “LoadScene(Scene Build Index);”:
If using the scene name, it must be exactly the same as what the scene is called in your project files.
If using the build index, it must be the same as the build index for the scene, found by going to “Edit/Build Settings”. Add all the scenes you want to include in the build, then use the index shown to the right of the scene name to load it.
There are also ways that you can change how scenes are loaded, such as “LoadSceneAsync”. Unlike “LoadScene”, “LoadSceneAsync” loads the specified scene in the background, while keeping the current scene loaded and running. This can be useful for a larger game that needs a loading scene when switching levels/scenes.