hi I need help getting to the next level on my puzzle game,
I want to get it so when it touches the exit it load the next level
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class LevelLoader : MonoBehaviour {
public string levelToLoad;
void OnTriggerEnter(Collider other)
{
SceneManager.LoadScene("levelToLoad");
}
}
is there any other way i could do it or am i doing something wrong please help
Thanks
You are declaring a variable called levelToLoad, but then in your function you’re giving it a hardcoded string (as denoted by quotes), instead of actual variable.
Change your line to:
SceneManager.LoadScene(levelToLoad);
And make sure you add your scene to build order.
- Open up the scene you wish to load next in your editor, so you can see it.
- Open File → Build Settings, and click “Add Open Scene”.
- You should now see both the scene you are coming from (assuming you added it), and the scene you wish to load in your build order.
Also, my advice is to use a scene index to load scenes, instead of a string representing the scene name.