Question by
ItzChris92 · Jul 19, 2020 at 10:13 PM ·
c#inheritancescriptable objectcasting
Inheritance and type casting problems
I'm in the process of building an inventory system. The inventory will contain a list of slots (also scriptable objects). I have an ItemObject abstract base class, and then multiple derived classes. I'm now wondering if this is a bad design as I foresee long switch statements and type casting in my InventorySlot script when I want to access properties/variables of the item it holds.
I was hoping someone might advise a more flexible solution?
public class Inventory : MonoBehaviour
{
public List<InventorySlot> slots;
}
public class InventorySlot : ScriptableObject
{
public Item item;
}
Comment
Your answer
Follow this Question
Related Questions
Property Drawers and Inheritance 0 Answers
Inheritance Question 1 Answer
Referencing Base Class In Prefab 0 Answers
How Do I Set A Parent Classes' Variables and override their functions 1 Answer