- Home /
Best Way to do Regular Items and Weapons/Intractable/Special Items.
I was just wondering if there was a good way to differentiate between a regular item and a special item in game.
To give a little more detail to what I am talking about, say you are playing a like Fortnite or PUBG. In Fortnite whenever you pickup an item such as Ammo or Building Materials, they are added to separate inventories, and in PUBG guns get their own special inventories.
Right now to determine if Items are have a special property, I just cast the pickup item as a Weapon (as Weapon extends off of Item)
public void PickupItem(Item item) {
if (item.type == ItemType.WEAPON) {
Weapon weapon = (Weapon) item;
// Do thing
}
}
I feel like this isn't the best way to do things, but that's kind of all I have right now. I am also using the type of enumeration to determine what type of interface said item is interfacing.
Basically, This question is kind of general. I am asking about the following points:
Is there a better way to implement item pickup besides checking an enum and then casting to another more specific type?
Should the base item class have methods that listen to input? I thought this would kind of be weird because you don't need an attack1() or attack2() method in an item like wood, but you would need them if you are making an Assault Rifle.
Currently my base Item class extends Monobehaviour so I can easily attach it onto objects, but I feel like because of this system, the Item Inventory might be a bit less inefficient. Should I split the current Item base class into a sort of Item Monobehaviour and another Item ScriptableObject/Class?
Answer by Shameness · Jul 02, 2018 at 07:22 AM
This is not long exact answer but you should really see this: https://unity3d.com/learn/tutorials/topics/scripting/inheritance .
Or this is better if can get grasp of it: https://unity3d.com/learn/tutorials/topics/scripting/interfaces .
Basically, you treat gun and material like they are same object. You pick them up, select them from their inventory, use them. But they are different. You save them to different inventory, etc.
Tell me if this helps to your issue.
That helps, but I am still wondering if my material item should have an attack()/reload() method?
Your answer
Follow this Question
Related Questions
Decorator pattern for inventory item class 0 Answers
Using enums to design an inventory system? 1 Answer
[SOLVED] Inventory Stacking Problem [C#] 2 Answers
How to add item to my inventory when I pick them up? 1 Answer
*What are some ways of implementing a Mid Mission Weapons/Upgrade/Equipment store? 0 Answers