- Home /
GUI only showing texture of the newest addition in the array. Help?
Hi all. 1st off, thanks to everyone that has helped me out a huge lot over the last few days. You guys really made my 1st steps into coding a lot more bearable than otherwise :)
Ok, problem time:
function OnGUI()
{ for (var g : GameObject in InventoryGrid) { items= g.GetComponent(ItemIdentifier).ItemTexture; } GUI.skin = MenuSkin; if (DisplayCharacter)
{ GUI.BeginGroup (new Rect(Screen.width*0.3,Screen.height*0.1,Screen.width*0.4,Screen.height*0.8));
GUI.Box(Rect(0,0,Screen.width*0.4,Screen.height*0.8),"");
for(i=0;i<InventoryGrid.length;i++)
{
GUI.Button(Rect(0+(i*Screen.width*0.05),0,Screen.height*0.05, Screen.height*0.05),items);
}
GUI.EndGroup (); }
^ So, basically I'm made an array to display the Icons (ItemTexture) found within an Item Script (ItemIdentifier) of Objects from my array (Inventory Grid)
^In the 1st photo, my inventory is empty. In the next one, I've added 5 maces. In the third, I added a new item with a blank texture and all the previous 5 textures were cleared. However, when i added another mace, now all the textures are maces again.
Answer by everett24 · Aug 30, 2014 at 07:51 PM
My best guess is that you should set your Items texture in the same spot you use it, ex
if(show inventory)
for(var i : int = 0; i < number of items in inventory; i++)
{
texture to use = item texture;
GUI.Button(Rect(0+(i*Screen.width*0.05),0,Screen.height*0.05, Screen.height*0.05), texture to use);
}
I think whats happening is that your item texture is being set to the last item in your inventory -Everett
Thanks for the suggestion. I actually spent a wholesomely long time to fix the issue, it required quite some recoding. $$anonymous$$aybe I'll try your method some time later on, looks quite a bit more efficient. Cheers anyways :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Deleting an Element from an Array. 1 Answer
How to make sound play once until called again 1 Answer
Sphere detection system 2 Answers
Using an array instead 2 Answers