inventory system help

hey guys. i am having trouble wrapping my head around how i would do an inventory system. i do not want to have to code in every single item in my game. say the player can have swords: i want to be able to create a base class called item. this would have a few public members/variables including price (float), name (string) and GuiIcon (texture)

there would be another class called sword that would inherit this. the player would have a list of item objects.

this is where the problem is. i want to use the sword class as i would any other script that inherits monobehaviour… i want to be able to attach it to an object and then in the editor define all of those public variables. i’d create an empty game object, attach it to an empty prefab, attach the sword script to it, and fill out the paramaters (100, Dagger, daggerIcon, for example…). i can create many different swords with this method…but to get it to work this way, it would mean that the base class, item, would need to inherit monobehaviour. if i do that, all instances of item are no longer just data…theyve become game objects. if i want a player to have 5 daggers, i would need to instantiate 5 daggers, and add those game objects to the players list of item objects. (his inventory… List inventory). it seems really inefficient to do this…and wrong. i just need to store the data, i dont need game objects. (The gameobjects would be handy when the player DROPS an item from his inventory though. because it is already a game object i can just render it into the world and drop it next to the players feet)., if i DONT inherit from monobehaviour, i cant use the script on various different prefabs to create various different swords. i’d have to hard code every sword in the game.

i hope i am making sense here… there is alot on my mind right now…! haha…

i just need some help understanding the best way to go about this.

I suggest you to store all items in one database not as game object. For example:

//database script who is attached to controler game object
var items : Item[];

class Item{
 var name : String;
 var model: GameObject;
 var price : float; 
 var type : ItemTypes;
}

enum ItemTypes{
 weapon=0,
 key=1,
 food=2
}

And to store items in playe invenory:

var myInventory : int[];
private var database : Database;

function Awake(){
  database=gameObject.Find("Controler").GetComponent("Database");
}

function OnGUI(){
 //draw list with all player items
 for (i=0; i<myInventory.length; i++){
  GUILayout.Label(GetItem(i).name);
 }
}

function GetItem(i : int) : Item{
 return (database.items[myInventory[i]]);
}

I hope this helps you.

yes i understand this, but from here on is where i am lost. (thanks for making it all a little clearer though heh) how can i actually define items now? say i want a dagger called ‘Dagger’. It costs 100 and is of type weapon. It has the model ‘dagger.fbx’. where do i define this information… thats the problem… i mean, i know i can instantiate an Item object through code, and set the variables, but i want to be able to define it through the editor, not through the code. im stuck in this annoying midpoint between having to use gameobject or a plain old database…argh!

You can edit database through editor in inspector - usually you are possible to do that. Simply attach database script to empty game object. It will be quite hard to mange big database but with small ones it isn’t problem. For big databases i would write editor script with witch i can easier to find, make and edit items.

Default inspector (for that example script):
593594--21125--$Bez nosaukuma.jpg
And how looks advanced editor(some while ago made it for my rpg

)