Random Audio Clip Help

Can you help me make a script where 7-8 audioclips play at random. Repeating is fine.

You can create an AudioClip array, then use Random.Range(0,audioClipArray.length) to select the sound randomly (Random.Range(0,max) draws an integer from 0 to max-1):

var sounds: AudioClip[]; // set the array size and fill the elements with the sounds

function PlayRandom(){ // call this function to play a random sound
    if (audio.isPlaying) return; // don't play a new sound while the last hasn't finished
    audio.clip = sounds[Random.Range(0,sounds.length)];
    audio.Play();
}

NOTE: Add an AudioSource to the object owner of this script.

ok, but maybe you have to use your brain abit and it will take an hour! in the process you will learn ALOT!

look at the play sound script in the UNITY REFERENCE… figure out how it works and make 7 8 variables for playing your sound…

Secondly look at the RandomRange variable…you use this to select randomly things. by making a random number from one to 8
http://unity3d.com/support/documentation/ScriptReference/Random.Range.html

Then… look at ARRAYS!!! fill an array with the varables for 7 sounds…

and then make a button like… if jump button then play random sound from 1 to 8. and when you have it loading, then change jump to whatever trigger you want.

var blocks : GameObject[]; ///declare an array except use soundobjects
var ino = Instantiate(blocks[Random.Range(0, blocks.Length)], displace2 + displace, rot);///

use a line like this except instead of instantiate, say … PLAY sound 1 to 8… blocks length is 8 if you have 8 sounds. using the oplay commands,

that is all, 3 lines, figure out how to use code!!!

you can alternatively declare and fill an array with this kind of logic:

var array2 = new Array (Vector3(0, 0, 0),Vector3(0,0,-90),Vector3(0, 0, 180),Vector3(0, 0, -270) , Vector3(90, 0, 0) ,Vector3(-90, 0, 0),Vector3(0, 0, 0),Vector3(0,0,90),Vector3(0, 0, -180),Vector3(0, 0, -270) , Vector3(90, 0, 0) ,Vector3(-90, 0, 0));

i’m sorry, i’m trying get a little help, but if you can’t help me… fine no problem :smiley: