- Home /
Question by
thornekey · Jul 30, 2015 at 03:01 AM ·
c#arrayaudiosourcemusic
AudioClip array error
Im getting this error:
Cannot convert type `UnityEngine.Object[]' to `UnityEngine.AudioClip' via a built-in conversion
Im trying to add a bunch of audio clips to an array without having to specify them all. I have a folder in my resources folder called 'songs'
Here is my code:
public AudioClip[] songsList;
void Start () {
songsList = new AudioClip[] {
Resources.LoadAll("songs", typeof(AudioClip)) as AudioClip
};
I have also tried it without the "typeof(AudioClip)" part, and also adding a cast before "Resources", but I cannot get it to work.
Comment
You're just missing the [] after the cast "as AudioClip[]"
Best Answer
Answer by Positive7 · Jul 30, 2015 at 05:54 AM
songsList = Resources.LoadAll<AudioClip>("songs");
or
songsList = Resources.LoadAll("songs", typeof(AudioClip)) as AudioClip[];