Currently building a game, with 4 levels, each with their own level trigger, but would like to have a system where it’s easy to add more, preferable storing them in some sort of list. The process for activating them would be done by:
Creating a level trigger > giving it a name / tag(ID) > (when triggered) search through a list for the level with the matching name / tag > then activate that level.
I was thinking of creating an abstract class “Level”, create a subclass of it “GetLevel”, then create methods within the subclass “LevelOne”, “LevelTwo” etc.
Is this the best way? And is anyone able to give a brief example of how it can be implemented?
i dont really understand why you need an abstract class and create a different class for each of the levels, what kind of methods those classes would implement?
i would go for an easier solution, a struct called levels like this (the id property is just in case you want to store it in a dictionary )
public struct Levels
{
public string id;
public int buildIndex;
public bool isActive;
public Level(string _id, int _index, bool _isActive = false)
{
isActive = _isActive;
buildIndex = _index;
id = _id;
}
}
all the levels saved in a dictionary
Dictionary<string, Level> levels = new Dictionary<string, Level>();
add the levels with your desired key
levels.Add("YourFirstLevel", new Level("YourFirstLevel", 1));
and when you want to access the index just access whenever you trigger by the key/tag
public int LevelByKey(string key)
{
return levels[key].index;
}