these are my object code and inventory code
I want when I Add a new class, it shows on GUI in a new Button
But it will change all the buttons!
what should I do?
Object Code:
#pragma strict
private var itemName : String;
var itemIcon : Texture;
var itemDesc : String;
//////////////////////////////////////////
function Start () {
itemName = this.gameObject.name;
}
function OnGUI()
{
if (GUI.Button(Rect(11,11,55,55),"Add") && Inventory.item.Count < 14)
{
var itemToAdd :itemClass = new itemClass();
Inventory.item.Add(itemToAdd);
itemToAdd.itemName = itemName;
itemToAdd.itemIcon = itemIcon;
itemToAdd.itemDesc = itemDesc;
}
}
Inventory Code:
#pragma strict
import System.Collections.Generic;
static var item = new List.<itemClass>();
class itemClass
{
var itemName : String;
var itemIcon : Texture;
var itemDesc : String;
}
//////////////////////////////////////////////////
function OnGUI(){
var xoffset : float = 0f;
for(i in item)
{
xoffset -=56;
GUI.Button(new Rect(800+xoffset,100,50,50),item[item.Count-1].itemName);
}
}