Level Load Script
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.
Answer by Nikaas · Apr 19, 2017 at 12:18 AM
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);
}
}
}
Your answer

Follow this Question
Related Questions
how i can link unity to my database and let users access their accounts on a login on the game 0 Answers
Why is my sprite invisible when infront of the background layers? 2 Answers
Is it possible to run a script that is not attached to an object? 1 Answer
How can I save values in an array using PlayerPrefs? 0 Answers
Minimap- in real time. 0 Answers