x


OneShotSound length?

How can I limit the length of a one-shot sound when changing the actual file is not enough? Do I have to flick mute on and off?

more ▼

asked Aug 13, 2011 at 08:14 AM

Muzz5 gravatar image

Muzz5
1.3k 206 171 184

You say you want to limit the length - does this mean make the entire audio clip play faster, or stop the audio clip before it's finished playing?

Aug 13, 2011 at 08:05 PM Julien.Lynge
(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

You can use audio.Stop() as well. It's better because it really stops the sound. With mute, the sound continues playing - and it will be "ressurected" if you fire a second sound before it has ended. You can use a coroutine to do it in a painless fire and forget fashion:

function PlaySoundLimited(sound: AudioClip, duration: float){
    audio.PlayOneShot(sound);
    yield WaitForSeconds(duration);
    audio.Stop();
}
more ▼

answered Aug 14, 2011 at 02:23 AM

aldonaletto gravatar image

aldonaletto
57.6k 33 92 302

(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:

x837

asked: Aug 13, 2011 at 08:14 AM

Seen: 946 times

Last Updated: Aug 14, 2011 at 02:23 AM