- Home /
Question by
marielamoller · Feb 29, 2012 at 03:45 AM ·
audiorandomloop
Pick random song at the biggining and then loop it the rest of the game
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.
Comment
Answer by adrenak · Feb 29, 2012 at 04:24 AM
To 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!
Your answer
Follow this Question
Related Questions
Is there a way to loop mp3 files seamlessly? 2 Answers
AoTTG - Modding with Visual Basics + .NetReflector SFX Mod 0 Answers
Random footsteps 5 Answers
Play Audio OnTriggerEnter then loop 2 Answers
Infinite loop when I try to generate randomly a 2D dungeon.. 3 Answers