This is the menu I am working on ImageShack - Best place for all of your image hosting and image sharing needs .
I declare my textures like var Item_0 : Texture2D; and the problem is what if I have 50 textures.Soo how can I organize this better.Second thing is I need to create a menu which works like this.GUI shows items one after other counting the integer which says how many items we have.Then there is item that is selected and it’s highlighted,different style.This all is textures with text only.And the selected item should be shown like first selected,second selected…till sixth and then the highlighted item should be in 6-th field.Then counting after six items should go for one forward and highlighted too remaining in field number 6…It sounds complicated but it’s just ordinary menu.
I hope you got some solutions,thanks ![]()
why don’t you use array?
var item : Texture2D[];
call one of them : item[0] or item[49] or item[35]
or all of them:
for (var i : int = 0; i < item.Length ; i++)
{
//do smth
}
or put all of those texture to Resource folder of your project, then use Resources.Load when you need to
I had exactly your problem in the game I just released. The backgrounds for all my levels were seperate texture2Ds.
My solution was to use a texture2D array just like Ovakin described.
Thanks,I thought of this before but I didnt know how exactly to call that texture out.I always use Custom counters that are int variable’s soo how could I use array with that just say:
if(Item_Count = = 0){
item[0];//do I have to have ; ?
}
Also I dont know how to add textures to array cuz I can add just one texture to array and I have like 20 of them,soo if you could clear this part to me soo I know a bit more ![]()
Soo if array doesnt work for me I would be interested in second option,can you put some little code?
After declaring the array, just drag and drop them from project window to inspector window.
I’m not sure I understand what you mean, but for example if you have an array named “itemTexture” which contains 20 textures, then call them by their order in the array, from 0 to 19, like itemTexture[0] when you need the first texture and itemTexture[19] if you want the last one.
And use something like this to load texture to gameObject from array:
var activeItemID : int;
var itemTexture : Texture2D[];
var itemDisplayer : GameObject;
function ChangeTexture()
{
itemDisplay.renderer.material.mainTexture = itemTexture[activeItemID];
}
And if you feel that drag and drop 20 of them is too tedious, create a “Resources” folder in you project, move all of your textures to a sub-folder in there named “ItemTextures” for example, then use this to load all of them:
function Start()
{
itemTexture = Resources.LoadAll("ItemTextures", Texture2D);
}
Thanks Ovakin very much ![]()
I didnt understand this array thing cuz to actually add more textures I needed to change array size,I think this will shorten my code for a lot.
And the example you showed me is great and I already know it,I just used some different names but I did the same as you,changed current texture by checking which number is int variable ![]()