I have a method to grab an item on my itemDatabase class:
public BaseItem GetItemByID (int id)
{
foreach (BaseItem item in itemDatabase)
{
if (item.itemID == id)
{
return item;
}
}
return null;
}
My inventory populates from this list by doing the following:
BaseItem itemToAdd = itemDatabase.GetItemByID (id);
inventory.Add (itemToAdd);
I am trying to do the same with a store, but when the item is added to my store list none of the variables are transferred. The list item is created but is blank. The code is pretty much the same as above and I don’t think I am missing any references!
BaseItem itemToAdd = itemDatabase.GetItemByID (1);
store.Add (itemToAdd);
Debug.Log ("Item added: " + itemToAdd.itemName);
The Debug here throws a null reference error as itemToAdd.itemName is null (obviously, this is the problem).
Does anyone know why this isn’t working in the exact same way as my inventory does??