Array index out of range. OR IS IT?

Script kiddie question, but this is driving me nuts.

Getting an array index out of range error. Staring at my code and trying to figure out why, and I have no idea.

public int[] crystalChance=new int[2];
public int[] crystalLosses=new int[5];

/*
...
*/

 void ResetCrystals()
    {
        for (int i = 0; i < 5; i++)
        {
            crystalLosses[i] = 0;  //Error here
        }
        crystalChance[0]=0;
        crystalChance[1] = 0;
    }

    }

For loop should run at a maximum index of 4. It then should reference crystalLosses[4]…which should be fine? Any idea what is causing the error? The error has persisted through multiple reloadings of both Unity and Visual Studio.

Unnecessary details: Enemies drop crystals (currency). You can shoot and destroy the crystals if you aren’t careful. If you do, your chance to get crystals dropping will increase 5 waves of enemies later.

Did you edit the array in the inspector?

1 Like

…yes I did. Thanks so much, been staring at this longer than I care to admit.