I wanna listen to a list of specific songs during the game in random order but I just know add only one song (at audio source). Is there a javascript for do this job?
Hey you could try doing something like this.
-
Make a list of audio files. Lists, unlike Arrays, are natively modular in size, meaning there is an .Add() method which allows me to add things infinitely, however with Arrays you must declare the size of it before allocating the songs.
-
So now lets randomly select a song. You could achieve this by creating a method called getSong(). In here you will do something like: currentSongID = (Random.Range(0,list.Count))
-
Now you just need to set the song in the audio source as currentSong[currentSongID]. Here you’ll want to have a conditional that checks to see if the auidclip has finished. If it has, then lets call getSong()
This is essentially what you’ll need to do. If I have time I could see about writing up some code to further explain, however you should try it yourself first.