First, Scenes that you want to use need to be added to the scene list.
Its under: File → Build Profiles → Open Scene List
public void onButtonPressed()
{
SceneManager.LoadScene(“Level1”);
}
This relies on the name of the scene file, and works perfectly fine for small projects.
public void onButtonPressed()
{
SceneManager.LoadScene(1);
}
This relies on the index the scene has in the scene list, and works perfectly fine for small projects.
First, open your scenes .meta file, and grad the GUID. This is a unique identifier that never changes (unless you delete the scene).
private string guidLevel1 = “guidOfyourScene”;
public void onButtonPressed()
{
private string scenepath = AssetDatabase.GUIDToAssetPath(guidLevel1);
SceneManager.LoadScene(scenepath);
}
This solution is usefull for big projects, or if you are a person that renames or rearrages stuff often.
Because the GUID never changes, this code will always open the correct scene.
Moving it to a different folder, raneming it, and changing its index in teh scene list all have no effect on this method.