How to set an array size automaticly?

In the picture where is “Inspector” you can see a script attached “Inventory”, in that script there is “Items” and “Equip Menu”, where is items the size is 7 of an elements and in “equip Menu” the size is 5 so i got a problem i need to trought script change “equip Menu” size to the itemsSize, how to do that?
ScreenShot: http://postimg.org/image/jtmq62kox/

Code:

// Equip Menu [	1.armor, 2.jewellery, 3.shield, 4.sword, 5.staff, 6.bow]
var EquipMenu : item[];

// Maybe something like this?!! tried.
EquipMenu.length = 10;
EquipMenu.size = 10;
EquipMenu[].length = 10;
EquipMenu[].size = 10;
EquipMenu = new item[10];

or try this
http://docs.unity3d.com/Documentation/ScriptReference/Array.html

2 Likes

Length just returns the size of the array. It doesn’t set it. You can’t use built in arrays like that. You’ll want to go with the array class which just from my brief googling looks like US has arraylist like in c#.

check this link

http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use?

No, do not ever use the Array class. It’s obsolete, and won’t show up in the inspector anyway. You wouldn’t use ArrayList either, for pretty much the same reasons. (ArrayList isn’t C#, it’s .NET, and can be used in any language, not that you would.)

–Eric

Thanks it worked.

EquipMenu = new item[10];

Does javascript have containers? if yes for game inventory is it smarter to use it or not? Maybe some examples how do you use it in unity?

JS has generic lists too.

var EquipMenu = new List.();

var EquipMenu = new List.<item>();

This is List i am talking about hashMap<>()?