So I am trying to put to together a script that will allow me to load thee next level. however i would like to be able to change the level to load in the inspector.
You can use the script below. To change the level you must call LevelLoad() method.
If you want to manually select the next level from the inspector then AltNext must be “true” (i.e ticked). If AltNext is false (not ticked) then the standard sequence of scenes will be used. You can see the number corresponding to each level/scene from File->Build Settings (next to each scene).
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelLoader : MonoBehaviour
{
public static bool AltNext;
public static int Level;
public static void LevelLoad()
{
if (AltNext)
{
Level = Mathf.Clamp(Level, 0, SceneManager.sceneCountInBuildSettings - 1);
SceneManager.LoadScene(Level, LoadSceneMode.Single);
}
else
{
int nextLevel = Mathf.Min(SceneManager.GetActiveScene().buildIndex + 1, SceneManager.sceneCountInBuildSettings - 1);
SceneManager.LoadScene(nextLevel, LoadSceneMode.Single);
}
}
}