- Home /
Is there a way to create a random Audiosource loop?
This is my problem: I want to play a random Audiosource within an array of Audiosource. And when it finishes, play another random Audiosourc from that array again. The audiosource doesn't have a end event, so I don't know when it finishes and I can't to play another Audiosource. I try it to use:
currentlyPlayingClip = Loops[UnityEngine.Random.Range(0, Loops.Length)];
currentlyPlayingClip.Play();
yield return new WaitForSeconds(currentlyPlayingClip.clip.length);
if (isPlayingInGame)
{
StartCoroutine(PlayRandomLoop());
}
But it does a little pause between the sounds. =/ Someone have an idea?
Answer by Screenhog · Jul 30, 2012 at 07:14 PM
Are you using MP3 files? MP3 is notorious for adding little bits of silence at the end, creating imperfect loops. Importing as WAV and then converting to OGG within Unity has worked better for me.
Answer by brunok8 · Jul 30, 2012 at 09:37 PM
I am using MP3 files. I'll try to do this way. Thanks!
EDIT: It works a lot better! But still seems that there is a little pause (i guess it's my .WAV files). THANKS!
Your answer
Follow this Question
Related Questions
Audio Manager 1 Answer
What could make the audio loop? 2 Answers
Audio cuts out once a certain number of sounds are played 0 Answers
PlayOneShot returns false for isPlaying 5 Answers
Play sound from an array, not random, and only once 3 Answers