Hello everybody. I cannot find solution by myself nor on internet. I have problems with static array in my script. I want to change size or initialize my Equipment menu in script so when i click inventory item button Item will go from generic MainInventar list to static Equipment array.
Here is code of my class:
public class Item{
var equipped: boolean;
var Name : String;
var Description: String;
var ItemQuantity: int;//quantity of item, f.e. potions, when U use it this is decrementing
var Health: int;//add healt when consumed
var Mana: int;//add mana when consumed
var MaxHealth: int;//add points to maximal health bar
var MaxMana: int;//add points to maximal mana bar
var Strenght: int;
var Intelect: int;
var Dexterity: int;
var Endurance: int;
var Damage: int; //attack power of weapon
var BloodDamage: int;
var AetherDamage: int;
var SolDamage: int;
var NyxDamage: int;
var Armor: int; //strenght of armor
var BloodResistance: int;
var AetherResistance: int;
var SolResistance: int;
var NyxResistance: int;
var Price: int;//shopping value of item
var ItemType: itemType;
var Rarity: rarity;
var icon: Texture2D;
enum rarity{
common,
uncommon,
rare,
mythic
}
enum itemType{
weapon,
helmet,
necklace,
armor,
gloves,
ring,
consumable,
miscellaneous
}
}
And here is part of my Inventar script where I want to initialize array of 5 Items.
var Equipment: Item[];
function Start () {
Debug.Log(Equipment.Length);
for(var z = 0; z < 5; z++){
Equipment[z] = new Item();
}
}
When I write size in Inspector, scripts is okay. Everything is fine. But when not, and I want ot add Item from list to array console says ArrayIndexOutOfRange, because it is not initialized.
But, is there way how can I initilize my Equipment array?
Thanks!
↧