Question by
RetroboltGames · Jun 15, 2019 at 12:20 AM ·
scenescene loadscene change
How's my SceneManager?
I looked up a few tutorials and made my own from a mish-mash of them.
I ask because, I tend to find out that there's a far better was that won't come back to bite me later on.
What I do is store the scene names in a enumeration, then create a string that will update when loading each new level and a bool to stop a domino effect with all the if statements. The string is made static so it keeps the same value.(Is it ok to use static to hold value between scenes?)
When the player completes a level the NextLevel method is called. If the player's in level 1, then go to 2 and so on, a if statement for each level.
What do you think of it, how can it be made better?
Thanks
public class SceneController : MonoBehaviour
{
public enum Levels
{
SL2_Level_001,
SL2_Level_002,
}
public static string currentLevel = Levels.SL2_Level_001.ToString();
bool skip = false;
public void NextLevel()
{
if (currentLevel == Levels.SL2_Level_001.ToString() && skip==false)
{
currentLevel = Levels.SL2_Level_002.ToString();
skip = true;
SceneManager.LoadScene(Levels.SL2_Level_002.ToString());
}
if (currentLevel == Levels.SL2_Level_002.ToString() && skip == false)
{
currentLevel = Levels.SL2_Level_001.ToString();
skip = true;
SceneManager.LoadScene(Levels.SL2_Level_001.ToString());
}
}
}
Comment