- Home /
How can I make a playlist last the whole gameplay?
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?
Answer by alyxlander · Dec 10, 2013 at 01:40 AM
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.
Your answer
Follow this Question
Related Questions
Audio is repeating. 3 Answers
On Mouse Click Play Sound 1 Answer
Playing Music Problem. 2 Answers
Changing Audio Pitch Dynamically 1 Answer
Random Audioclip. No Repeat ?? 1 Answer