Hello. I tried to make a Survival game but I am very confused. now let’s say I have an inventory system. In this InventorySystem there is a List Value that holds ItemClasses. When I use the Use(ItemClass UsingItemClass) function, I give the UsingItemClass value and this value I give is MagazineClass inherited from an ItemClass. now inside this Use function there is code that finds a class inherited from the ItemController class. let’s say it found MagazineController and used the Intialize(ItemClass Item) function inside MagazineController.
Let the Intialize Function be something like this:
public override void Initialize(ItemClass itemClass)
{
Debug.Log("Item Class: " + itemClass.ItemID);
magazineClass = itemClass as MagazineClass; // Convert to MagazineClass
Debug.Log("Magazine Class: " + magazineClass);
base.Initialize(itemClass);
...............................................
}
But this function “Debug.Log(”Item Class: “ + itemClass.ItemID);” returns something but “Debug.Log(”Magazine Class: “ + magazineClass);” returns null. Why?
How can I access MagazineClass from ItemClass?