In the project where I work (with Unity 2017.3) I must use a single scene for all levels of the game. Each level has its class with its particular implementation, but they all inherit from the Level.cs class. What I need is to store the levels in such a way that what I save in a serialized file is only an index int to look for the script of the level where the player is left.
Base level:
public class Level
{
public int id;
public string name;
public Level()
{
}
public void ConfigureLevel(StageObject stage)
{
//some stuff
}}
Here is a particular level:
public class Level_1: Level
{
int try= 0;
public Level_1(StageObject stage)
{
base.id= 0;
base.ConfigureLevel(stage);
}}
Here is the levelmanager that should be able to store the levels for then with the saved data instantiate the current level and not the first one:
public class LevelManager : Singleton<LevelManager>
{
Level currentLevel;
Stage stage1, stage2, stage3;
void Start()
{
//load saved data and player prefs
currentLevel = new Level1(stage1); // For now I am always loading level 1,but I want to load the last one visited (the saved level)
}
}