Trouble with instantiating from a List<>

Here’s the rub: I have a loot table for a game I’m working on. Originally, it was an array of objects that could spawn when you opened a chest. Now I want that loot table to be dynamic based on a player’s actions- Things may get added or removed as time goes on.

Because I wouldn’t know the size of the array, it was suggested that I use a List<>. Easy enough to set up, but I can’t seem to instantiate FROM a list.

Doing this (Where tempO is a GameObject and lootTable is a List<>):

tempO = lootTable(1);

Gets me this error:

Assets/_scripts/spawnManager.cs(35,33): error CS1955: The member `spawnManager.lootTable' cannot be used as method or delegate

My question: Why? And SHOULD I be using a List<>? What are my other options?

You probably want this:

tempO = lootTable[1]; //note the square brackets

A List is close to an array of T[], plus a few extra features. The most important extra feature is that it will dynamically resize if you try to add elements past its current capacity.

JavaScript’s Array() class accomplishes much the same thing, but isn’t always well-suited for use with strict/static typing.

As for the rest of your question, the Unity wiki has a good article: Which Kind Of Array Or Collection Should I Use?