- Home /
Question by
James_Beavers · May 08, 2013 at 02:07 PM ·
objectsoundmultipleplay
Playing a range of sounds from an object
This might seem like a question people have posted but I want something different from mine. So far I have a script that looks like this which allows the play once of a sound.
var Sound : AudioClip;
private var hasPlayed = false;
function OnTriggerEnter(){ if(!hasPlayed){ audio.PlayOneShot(Sound); hasPlayed = true; } }
What I'm wanting is to have a range of sounds play, To have 3 different audio files and to have a randomised chance of playing each one, or better yet play the three in order. but separately after each time the player enters the trigger. I found something that looked like this but I don't know how to implement it. can anyone help me out?
var sounds: AudioClip[]; // fill this array in the Inspector
var SkateboardRoll: AudioSource;
...
// choose a random sound to play:
SkateboardRoll.clip = sounds[Random.Range(0, sounds.length)];
SkateboardRoll.Play();
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613101828im_/https://answers.unity.com/themes/thub/images/avi.jpg)