I´m building a game, and i have tree diferent songs. I would like it to pick one random at first but then to loop it in the rest of the game.
1 Answer
1To do this you can make an array of AudioClip variables and assign your music there, then chose a random song and play it. Here’s a code :
var musicList : AudioClip;
var currentMusic : AudioClip;
function Start(){
audio.loop = true; //to loop the music
currentMusic = musicList[Random.Range(0, currentMusic.Length)]; //randomly chose a music
audio.clip = currentMusic;
audio.Play(); //play!
}
I Hope this helped!