- Home /
Question by
Chizukoo · Jan 11, 2019 at 10:43 AM ·
arrayaudioaudiosourceaudioclips array
make audio array and play random
I want to make an array of audioclips and then play them randomly. But how do I make the array with the audioclips?
public class audiomonsters : MonoBehaviour {
public AudioSource randomSound;
public AudioClip[] audioSources;
public
// Use this for initialization
void Start()
{
audioSources = Resources.LoadAll<AudioClip>("Resources, Sound");
//audioSources = Resources.LoadAll("Resources, Sound", AudioClip);
//var allsongs[]= Resources.LoadAll("Resources, Sound", AudioClip);
CallAudio();
//audioSources = new AudioClip[10];
}
void CallAudio()
{
Invoke("RandomSoundness", 10);
}
void RandomSoundness()
{
randomSound.clip = audioSources[Random.Range(0, audioSources.Length)];
randomSound.Play();
CallAudio();
}
}
Comment
Answer by L42yB · Jan 11, 2019 at 11:34 AM
Just change you code to this:
audioSources = Resources.LoadAll<AudioClip>("Sound");
Assuming your audio files are in the directory "Resources/Sound" then this will work.