ARTICLE AD BOX
public Dictionary<string, int> inventory = new Dictionary<string, int>();
public List<string> itemNames;
public List<IslandPrObject> islandTypes;
...
foreach(string item in itemNames)
{
if(inventory[item] != Null)
{
if(inventory[item] >= islandTypes[island].GetField(item))
{
inventory[item] -= islandTypes[island].GetField(item);
}
}
}
This is Unity C#, but I believe the question is applicable with all uses of C#, I want to be able to locate a variable using the item name, for example:
islandTypes[island].item
The main premise is so that I can simply add items to the "itemNames" list, and the code should automatically check the cost fields of the "islandTypes" list.
How could I go about accomplishing this?
