Help with arrays

Hi, I am working on a script to play a sound when an object hits the ground. I have 4 hit sounds, and I added them as an array variablevar hitSound : AudioClip[];

But I dont know how to play a random sound out of that array. Could someone fill me in on how arrays work?

i have no clue as to the specifics of the language but…

why not have a function which generates a random number between 1 and 4, and just grab the array value corresponding to it?

like
DiceRoll() //outputs variable random of type int
var hitSound : AudioClip[random];

See the FPS tutorial. The player has random pain sounds and footsteps.

Wait, so an array value is like :audio.PlayOneShot(sound[1]);

Right?

Yes, that is basically how they work.

You can pick random elements from an array using something like:-

var chosenOne = optionArray[Random.Range(0, optionArray.Length)];