bromley
1
I want to play a sound with a loop but I don’t want that when the sound reaches the end it starts to the beginning. Is it possible to create a loop from the middle of the sound instead of from the start?
Maybe the answer is using SetScheduledStartTime() and PlayScheduled(), but I don’t understand how.
Please help!!!
bromley
2
Nevermind, I found a solution on my own. If you are interested this is the method:
IEnumerator PlayCustomLoop (AudioSource sound, float endIntro)
{
sound.loop = false;
float l = sound.clip.length;
int t = 0;
sound.Play ();
yield return new WaitForSeconds (endIntro);
t = sound.timeSamples;
yield return new WaitForSeconds (l - endIntro);
LOOP:
sound.timeSamples = t;
sound.Play ();
yield return new WaitForSeconds (l - endIntro);
goto LOOP;
}
Unfortunately you have to know first the value endIntro, namely the time in which the sound has to start the loop.
I hope this can help you.