Array index is out of range

Hi, I have these code, but always get "Array index is out of range" error.

var vertices : Vector3[] = new Vector3[10];

function Update () {
            vertices[0] = new Vector3( 1, 1, 1);

can someone help me to solve this problem?? thanks.

Make the array private

Unity will use the inspector version of the array for any public arrays, and since you probably didn't fill values in there, it'll assign a 0 length array

private var vertices : Vector3[] = new Vector3[10];

Don't initialize class variables at declaration time, doing it in Awake() or Startup() is the proper way to do it.

I have same problem when use followin code on Player

var healthTex: Texture2D[]; // define the size and fill its elements in the Inspector

static var LIVES = 6;

var healthImage: Texture2D;

var healthImageOffset = Vector2(0, 0);

var nativeVerticalResolution = 1200.0;

function Update(){

guiTexture.texture = healthTex[LIVES];

DrawImageBottomAligned( healthImageOffset, healthImage); 


function DrawImageBottomAligned (pos : Vector2, image : Texture2D)


GUI.Label(Rect (pos.x, nativeVerticalResolution - image.height - pos.y, image.width, image.height), image);