- Home /
How to display textures that are in an array?
Im trying to create an inventory system but im not having to much success. Im trying to figure out how to add a texture to an already created button if a variable is true. Can anyone help? Here is my code for opening the inventory:
var Inventory = new Array();
var emptySlot : Texture;
var showInventory = false;
var ex1 : float = 2.8;
var why1 : float = 5.8;
var exBig : float = 200;
var whyBig : float = 200;
var ex2 : float = 2.8;
var why2 : float = 5.8;
var sword = false;
var swordTexture : Texture;
function Update ()
{
Debug.Log(Inventory.length);
if (Input.GetKeyDown(""))
sword = true;
}
function OnGUI ()
{
if (GUI.Button(Rect(Screen.width-100, Screen.height/2-50, 100, 100), emptySlot))
{
if (!showInventory)
{
showInventory = true;
}else{
showInventory = false;
}
}
if (showInventory)
{
GUI.Box(Rect(Screen.width/ex1, Screen.height/why1, exBig, whyBig), "Inventory");
for (var x=1; x<6; x++)
{
for (var y=1; y<6; y++)
{
if (GUI.Button(Rect(Screen.width/ex2+x*50, Screen.height/why2+y*50, 50, 50), emptySlot))
{
}
}
}
}
}
Is there a way to where if sword = true then it shows the sword texture in the first open slot?
I have retagged your question. "for" is not a tag
Also Duplicate Question:
http://answers.unity3d.com/questions/205239/inventory-simple-and-easy.html
http://answers.unity3d.com/questions/40280/making-an-inventory-basics.html
http://answers.unity3d.com/questions/topics/inventory.html
http://answers.unity3d.com/questions/11090/how-can-i-create-an-inventory-system-with-gui.html
http://answers.unity3d.com/questions/399383/inventory-help-1.html
http://answers.unity3d.com/questions/401369/inventory-help-3.html
http://answers.unity3d.com/questions/401901/can-someone-help-me-with-an-inventory.html
http://answers.unity3d.com/questions/401327/best-way-to-implement-rpg-inventory-system-w-sized.html
All just from a simple google search!!
Answer by Benproductions1 · Feb 20, 2013 at 03:20 AM
If your only problem is displaying and selecting the correct texture, this should solve it:
//In your nested for loops
GUI.Button(Rect(/*your rect*/), Inventory[x][y]); // if Inventory contains textures
//If your inventory contains texture indexes and you have a list for textures
GUI.Button(Rect(/*your rect*/), Textures[Inventory[x][y]];
Remember that there are so many ways you could make an inventory for any game. It's hard to say specifically with the information give, but this should provide at least a hint as to what you should do
Hope this helps, Benprductions1
Your answer
Follow this Question
Related Questions
Repositioning remote GUI Texture 1 Answer
inventory system - change GUI.DrawTexture texture 3 Answers
need to shorten my code but unsure of how 3 Answers
Remove Items and Item Tooltips 0 Answers
How can i show the texture in the array? 2 Answers