enter code here
I’m quite confused by this little issue. I’ve dealt with arrays and classes before, but clearly I’ve made some sort of mistake. I keep getting Array Index is out of range on the line:
Equip(AllSkills[0],0);
AllSkills, the Array of the class “Skill” has members in it… as does SkillSlot(Though I believe the out of range is refering only to AllSkills). I added these members in the inspector and they are filled out.
What is my mistake?
class Skill {
//Active or Passive
var Active : boolean;
//SkillObject
var TheObject: GameObject;
var CooldownCurrent : float;
var CurrentStamina : int;
var StaminaCost : int;
}
var AllSkills : Skill[];
var SkillSlot : Skill[];
function Equip ( NewSkill : Skill, Slot : int ) {
SkillSlot[Slot] = NewSkill;
if (!SkillSlot[Slot].Active) {
Instantiate (SkillSlot[Slot].TheObject,transform.position,transform.rotation);
}
}
function Activate ( Slot : int ) {
if (SkillSlot[Slot].CooldownCurrent == 0 && SkillSlot[Slot].StaminaCost < CurrentStamina ) {
if (SkillSlot[Slot].Active) {
Instantiate (SkillSlot[Slot].TheObject,transform.position,transform.rotation);
}
}
}
function Update () {
if( Input.GetKeyDown(KeyCode.Alpha1)) {
Activate(1);
}
if( Input.GetKeyDown(KeyCode.Alpha2)) {
Activate(2);
}
if(Input.GetKeyDown(KeyCode.T)) {
Equip(AllSkills[0],0);
}
}