Inventory Class Problem.

Im trying to make an inventory where you click on the gui button and it goes through the variables of the items class, but when i get down to the items name variable it comes up with a error;
‘InventoryItem’ is required to access non static member ‘ItemName’.
if i change it to a static variable it will never change and update. making all the inventory objects the same as the last one picked up.

class InventoryItem{
   var worldObject : GameObject;
   var texRepresentation : Texture2D;
   var ItemName : String;       /////////The variable im trying to access/////
   var ItemClass : String;
   var ItemDescription : String;
   var Damage : int;
   var Defence : int;
}

//////////This is in the ongui function//////
if (currentInventoryItem != null  GUI.Button(new Rect(offSet.x+k*(iconWidthHeight+spacing), offSet.y+i*(iconWidthHeight+spacing), iconWidthHeight, iconWidthHeight ), _itemName, GUIStyle("Button"))){

       if(_itemClass == "Potion"){ 
		Potion();
		inventory[i][k] = null;	
     	}

////////////This is separate///////
function Potion(){
   	_itemName = InventoryItem.ItemName;
   	useing = true;
	if(_itemName == "Health Potion"  useing){
		 Debug.Log("healthption");
         }
}

You have to cearte an instance of the class :

class Test {
	var Username:String;
}

var t:Test = new Test ();
t.Username = "myName";
var itemName : InventoryItem = new InventoryItem();
	itemName.ItemName = "";

Am i doing something wrong, i get no errors but nothing seems to be working.

I’m not sure how you made your items for your Inventory. But inorder for an Item to be picked up it has to have a Script attached to it. For mine that is. Such as mine is called ObjectInfo ( Was from Design3 tutorial, Heavily Altered* )

if(myInventory[curIndex].GetComponent<ObjectInfo>().item.useItem.isUseable)
{
   //Its a Usable Item Heal/Regen/Buff Potion
   ObjectInfo.Instance.usePotion(myInventory[curIndex], curIndex);
   return;
}

Very cool RPG btw. Liked the youtube videos. If you need any other help with Inventory let me know. I’ve added Stackable Potions, MouseOver tooltip, AutoEquipable right click, Auto-DeEquip Right click, Use potion Right click.

Skype : imcanida

I can’t see if anything else is wrong but i tested it :

#pragma strict
var item:InventoryItem;

class InventoryItem {
   var worldObject : GameObject;
   var texRepresentation : Texture2D;
   var ItemName : String;       /////////The variable im trying to access/////
   var ItemClass : String;
   var ItemDescription : String;
   var Damage : int;
   var Defence : int;
}

function Start () {
	item = new InventoryItem ();
	item.ItemName = "test";
}

function OnGUI () {
	if (GUILayout.Button ("test")) {
		Debug.Log (item.ItemName);
	}
}

No problem, works perfect.

Thank you so much for your help, finally got it to work!
Thank you, thank you, thank you!