- Home /
Implementing an Item system - Defining Items
So i'm just not entirely sure how I should go about doing this.
Right now I have an Item class, and then I have a weapon class, armour class etc which all inherit from Item.
I just don't know how I define all the items in my game. For example, If i want 3 weapons, one called "Bronze Sword" one "Rusty sword" and one "Steel sword" how do I define them as a Weapon (using the weapon class) And set all they're properties? Should I make a separate script for each one? Or a separate prefab? I don't know how I should go about doing this...
Any suggestions?
Thanks
Answer by Olgo · Jun 25, 2013 at 06:37 PM
Hey there, I've recently started doing research on this same topic. I think the best answer that came up so far was this:
http://answers.unity3d.com/questions/155003/item-database.html
I believe the "hardcoded" example would be easiest but most time consuming. It has spurred me to look in to a database style system where I could maybe export an XML file from an excel sheet.
Ok I think this should work... I'll have to experiment with it a bit first.
Ahhh, I've been experimenting with that a bit, and it seems to be working perfectly! Thaanks!
Old topic, but just as relevant today as it was in 2013. Be careful with the above example. All items have exactly the same properties. No more, no less.
This is unlikely to happen in a real game. You wont get dexterity on an apple but you might on a cloak. This means you'll have a root structure of classes that inherit all the way back to your item class.
The most flexible way to do this is with X$$anonymous$$L and have it automatically create the class structure for you based on the X$$anonymous$$L itself.
Your answer
Follow this Question
Related Questions
Serialized class, Instances and access 1 Answer
Class Programming to build an inventory system 3 Answers
Best practice for defining items in advance? 1 Answer
About Classes in js 2 Answers