- Home /
Another Inventory Script with pictograms
I need a help with inventory scripts I found here on forum page. I modified it a bit and tried to applied for my
project, but Unity generate an error. I'm new to scripting and asking you about help. Here is my Inventory code (TInventory.js):
public var items = new System.Collections.Generic.Dictionary.<String,GameObject>(); public var itemsT = new System.Collections.Generic.Dictionary.<GUITexture,GameObject>(); private var curItem : System.Collections.Generic.KeyValuePair.<String, GameObject>; private var curItemT : System.Collections.Generic.KeyValuePair.<Texture, GameObject>;
public var buttonHeight = 100; public var width = 100;
function AddItemToInventory (item : GameObject, rndTexture : Texture) { items.Add(item.name, item);
// There is an error here itemsT.Add(rndTexture.texture, rndTexture); // }
function OnGUI() { var curIndex = 0;
GUI.BeginGroup (new Rect (0, 100, 100, 400));
for(var rndTexture : System.Collections.Generic.KeyValuePair.<Texture, GameObject> in itemsT) {
var rect : Rect = new Rect(0, buttonHeight * curIndex, width, buttonHeight);
if(GUI.Button(rect, rndTexture.Key)) {
curItemT = rndTexture;
// USE ITEM // RemoveItem(item); } curIndex++; }
GUI.EndGroup();
}
I attached it to the empty GameObject in Unity. My idea is to collect objects using OnMouseUp() function at game scene and show those as pictograms with using
array of textures assigned as picto variable. I wrote another script for a collect able objects and add it for gameObject (for example: knife.js):
var picto : Texture2D;
function OnMouseUp () {
var Inventory = GameObject.Find("inventoryButton");
Inventory.SendMessage ("AddItemToInventory", this.gameObject);
Destroy(gameObject);
}
TInventory script creates array of objects but I have problem with showing pictograms textures. Unity generates
this error:
Assets/TestScripts/TInventory.js(11,32): BCE0019: 'Texture' is not a member of 'UnityEngine.Texture'.
How to display those textures which represents game objects and place them into array?
Your answer
Follow this Question
Related Questions
GUI.DrawTexture on GUI.Button press 1 Answer
Fade script working but I can't 'see' it working? (Solved) 1 Answer
GUI.Box not showing Texture on device 1 Answer
Toggle GUITexture V.2 1 Answer
Web player screen corruption 1 Answer