Game Development Reference
In-Depth Information
void Playlist()
{
if(!audio.isPlaying)
{
if(curSong > SongList.Capacity)
{
curSong = 0;
}
else
{
curSong++;
}
audio.clip = SongList[curSong];
audio.Play();
}
}
The first thing that we check for when running this function is if there is already a
song playing. If there is a song playing, the code will wait until the song stops; if there
is no song playing, our code gets executed. To execute the code, we use the iterator
variable that we created earlier; if the value is higher than the number of songs we
have, we reset it to zero.
If the value of the iterator variable is less than the number of songs we have, then we
iterate it and move on to selecting our song. To select the next song to be played, we
grab it from the AudioClip list and assign it to the clip property of the GameOb-
ject's AudioSource component. Lastly, we call the Play function of AudioSource
to play the song.
Implementing the audio systems
Now that we have created our two systems to play music, we will need to finish off
our script with a few other features. First, we will create the Start and Update func-
tions as they will be needed for this script to work:
void Start()
{
Search WWH ::




Custom Search