Instructions: 1 - attach this to any gameobject 2 - place the gameobject with the AudioSource component to mySource 3 - Lets say you have 3 audio clips you want to use, set both Range Scan and My Audio Elements to 3 4 - add your 3 clips as elements 5 - Enable Debug to get a list of the clips on the console but they also show on the editor as you play the game
Tips: this is on enable, so everytime this object is enable its gonna run a new range and assign the clip, Hope it helps took me about 5 minutes, if this helps you please consider following my facebook dev group HERE
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class randomSound : MonoBehaviour {
public AudioSource mySource;
public int rangeScan;
public AudioClip[] myAudio;
public int toPlay;
public bool debugging;
void OnEnable () {
toPlay = Random.Range(0,rangeScan);
if (debugging) {
foreach (AudioClip value in myAudio) {
print (value);
}
}
mySource.PlayOneShot(myAudio[toPlay], 0.9F);
mySource.Play ();
}