Playing Random Audio from array?
So I've managed to build the array using code from the first person controller standard script in unity. However it doesn't play the sound when I 'void OnTriggerEnter' the collision radius of the audio source, any suggestions?
Answer by RealMTG · Feb 03, 2017 at 02:42 PM
Maybe it's not playing because whenever you enter the trigger, as a player I presume, you return, i.e, stopping the code there. If you have a tag called "Player" on the object that enters the trigger, then you should remove the
if(collider.gameObject.tag == "Player")
{
return;
}
Answer by BillooC · Feb 03, 2017 at 03:28 PM
Hey thanks that helped, although it didn't let each individual clip play through its entirety before starting the next clip. There are other instances when I would like an array to only pick a sound once the player has collided with a certain area.
Your answer
![](https://koobas.hobune.stream/wayback/20220612110204im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Sound is not playing from Script 1 Answer
Soundarray for player is not working properly 1 Answer
On Off sound 0 Answers
Audio Source does not contain definition for any of the Play functions... 2 Answers