triggering random animations with gui

I have a GUI button that triggers an animation. But I want it to trigger animations randomly every time it is pressed. So that the game object which has 10 animations ( spin1,spin2,..)are played randomly each time the trigger is pressed. BUT due to my inexperience I dont really understand arrays. What I have at the moment is simply this

function OnGUI() {

if(GUI.Button(Rect (250,0,600,1000), " ")){

    animation.CrossFade("spin2");

} }

but i have so far changed it to something like this

function OnGUI() {
if(GUI.Button(Rect(250,0,600,1000),"test",customButton)){
    animation.CrossFade(Random.Range(0,animation.elementCount));

}
}

Thanks for any help.

You need to store the animation list in an array or you can store the name of the animation in a String array, which ever you prefer

e.g.

var animName : String[];

function OnGUI() {
   if(GUI.Button(Rect(250,0,600,1000),"test",customButton)){
       animation.CrossFade(animName[Random.Range(0,animName.length)]);
   }
}

You set the size and fill the array with names in the inspector. You return the contents array by typing the name of the array followed by square brackets with a number inside. Remember that arrays start from 0 and not 1.

e.g.

print(arrayName[1]);

Array docs:

http://unity3d.com/support/documentation/ScriptReference/Array.html

Typical array functions:

http://msdn.microsoft.com/en-us/library/system.collections.arraylist_members(VS.80).aspx