x


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

more ▼

asked Jan 26 '12 at 12:03 AM

RMsoftware1 gravatar image

RMsoftware1
31 4 7 9

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.

Jan 26 '12 at 12:06 AM Lo0NuhtiK

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.

Jan 26 '12 at 12:11 AM RMsoftware1

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.

Jan 26 '12 at 12:17 AM syclamoth

Ahh, I see... BUT... How would you switch the sounds?

Jan 26 '12 at 12:20 AM RMsoftware1

change audio.clip to the new sound after the end of the coroutine. Come on, this isn't that hard.

Jan 26 '12 at 12:28 AM syclamoth
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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();
}
more ▼

answered Jan 26 '12 at 01:09 AM

syclamoth gravatar image

syclamoth
14.8k 7 15 80

Thanks, I never thought of that... :)

Jan 26 '12 at 01:50 AM RMsoftware1

OK, used it... I like it, it works!

Jan 26 '12 at 02:04 AM RMsoftware1

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

Apr 10 '12 at 10:04 AM cmos

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.

Apr 12 '12 at 12:36 AM syclamoth
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3462
x1029
x525
x296

asked: Jan 26 '12 at 12:03 AM

Seen: 817 times

Last Updated: Apr 12 '12 at 12:36 AM