For a mining game I have a public static dictionary that I was hoping to use to sort for calling by id, but I can’t get it to call values from the dictionary. If I call a debug.log(dictionary.count.tostring()) it shows me that it is in fact 16 long, but all the values are null. I don’t understand, and am currently calling item specifically, but this will make it very hard for me to call random items from a pool down the road.
public static class Resources {
public static Dictionary<int, Item> ResourceDictionary = new Dictionary<int, Item> {
{0, null},
{1, Resources.RawOre},
{2, Resources.Gem},
//etc
};
}
PlayerScript.AddItem(Resources.RawOre, 10);
//^^^^this works fine, calling directly
for (int i = 0; i < newGems; i++){
int gemType = Random.Range (10,15);
PlayerScript.AddItem(Resources.ResourceDictionary[gemType], 1);
//calling through the dict returns null reference exception
}