I have a list of LevelPieces to make up a game level.
public List sourcepieces = new List ();
containing however many pieces for a single level.
I now want to add levels, so I need either an array of sourcepieces or a list of sourcepieces.
I can then have a variable for level, and produce my list of levelpieces based on which level I am on.
I’ve searched a little but am struggling to get my head around a) whether an array or list is better and b) how it is done syntactically.
I may need to save these lists out at some point, and there seems to be a suggestion that lists of lists are not serializable/savable - is that true?
Anyway, I’ve tried doing the following:
public List<SourceLevelPiece> sourcepieces = new List<SourceLevelPiece> ();
public List<sourcepieces> sourcepieceslist = new List<sourcepieces>();
which would give me a list of my list of pieces (sourcelevelpieces) but it doesn’t like the last line.
I can get the following to compile, but not sure that is right.
public List<List<SourceLevelPiece>> sourcepieceslist = new List<List<SourceLevelPiece>>();
As I presumably want a list of sourcelevelpieces rather than a list of SourceLevelPieces (which I already have)
And once I have my list of lists, how do I go about adding a) a new main level to the list and b) adding the subobjects for the main level list.
Sorry, I probably haven’t got a lot of the terminology right. I’ve tried using the latter syntax above but I’m a bit stuck now working out what syntax to use to even access them.
I basically need to replace:
SourceLevelPiece sourcepiece = Instantiate(SourceLevelPiece);
sourcelevelpieces.Add (levelpiece);
with something along the lines of
SourceLevelPiece sourcepiece = Instantiate(SourceLevelPiece);
sourcepieceslist[0]. Add (sourceLevelPiece);
but again the syntax completely alludes me.
This is all working with a single List. I just need to amend my code to convert the single list to a list of lists and reference the one I want with a index int.
Thanks in advance.