I have an inventory script that creates an a button at the bottom of the screen for the items in the inventory, but I am encountering an issue as it currently simply has text, where as I want a different image in each box.
I have linked the script below to show my issue:
#pragma strict
var obj_wood : GameObject;
var obj_claw : GameObject;
var obj_bread : GameObject;
var obj_water : GameObject;
var numberOfItems : Number;
public var items = new System.Collections.Generic.Dictionary.<String,GameObject>();
private var curItem : System.Collections.Generic.KeyValuePair.<String, GameObject>;
public var buttonHeight = 50;
public var width = 100;
AddItemToInventory(obj_wood);
AddItemToInventory(obj_claw);
AddItemToInventory(obj_bread);
AddItemToInventory(obj_water);
function AddItemToInventory (item : GameObject) {
items.Add(item.name, item);
Destroy(item);
}
function OnGUI() {
var curIndex = 0;
GUI.BeginGroup (new Rect (400, 300, 400, 120));
for(var item : System.Collections.Generic.KeyValuePair.<String, GameObject> in items) {
var rect : Rect = new Rect((width+2) * curIndex, 0, width, buttonHeight);
var itemTexture : Texture = "icon_"+item.key;
//i have called each texture icon_“item name”, but the texture variable wont accept a string
if(GUI.Button(rect, itemTexture)) {
curItem = item;
RemoveItem(item);
}
curIndex++;
}
GUI.EndGroup();
}
function RemoveItem (item : System.Collections.Generic.KeyValuePair.<String, GameObject>) {
yield WaitForEndOfFrame;
items.Remove(item.Key);
}
function RemoveItem (item : GameObject) {
yield WaitForEndOfFrame;
items.Remove(item.name);
}
if you have any idea of how too this it would be appreciated thank you