- Home /
VERY irritating.... I need help with playing and switching sounds in Javascript code...
Hello, Again, I have two sounds, ok, and one is an intro sound, the other is a looped sound... I want this to happen:
When the scene loads I want the intro sound to play, When that sound is finished playing, I want the second sound to play in a loop.
The problem:
I have not the slightest clue on how to do this :( Please help me :(
Thanks a ton
How is it very irritating when you say you haven't a clue how to do it. If you had tried and failed and tried some more and failed some more, and then tried again, you would be very irritated... but... you would have a clue.
Well, you see, I have been reading around, and all those answers failed to work, thus i am very irritated. I also have no clue on how to make it work.
A funny coincidence- I was just looking through the scripting guide, and I came across this. Isn't this exactly what you need? You should read the entire script reference, cover to cover, and then you will know more about Unity than about 90% of the people on this site.
Ahh, I see... BUT... How would you switch the sounds?
change audio.clip to the new sound after the end of the coroutine. Come on, this isn't that hard.
Answer by syclamoth · Jan 26, 2012 at 01:09 AM
Fine fine here have a free script.
var startingSound : AudioClip;
var loopingSound : AudioClip;
function Start()
{
audio.clip = startingSound;
audio.Play();
PlayQueued(loopingSound, true);
}
function PlayQueued(next : AudioClip, loop : boolean)
{
yield WaitForSeconds(audio.clip.length - audio.time);
audio.clip = next;
audio.loop = loop;
audio.Play();
}
I am having a problem, it works but there is a little space inbetween both sounds. I want it to play seamlessly. Any ideas?
Thanks, Chirs
Look around, cmos, and you'll find a few detailed discussions on this matter. Basically, there's no really elegant solution, other than using an external sound library.
Your answer
Follow this Question
Related Questions
Can't get a sound to loop 2 Answers
Have readout of score at certain increments (JavaScript) 1 Answer
Playing multiple sounds with multiple subtitles 1 Answer
Audio Needs to stop 1 Answer
Audio loop after time 2 Answers