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");
}
}
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* )
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.
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);
}
}