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 '11 at 08:14 AM

Muzz5 gravatar image

1.3k 81 87 94

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 '11 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){
    yield WaitForSeconds(duration);
more ▼

answered Aug 14 '11 at 02:23 AM

aldonaletto gravatar image

55.3k 21 64 261

(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



Answers and Comments



asked: Aug 13 '11 at 08:14 AM

Seen: 787 times

Last Updated: Aug 14 '11 at 02:23 AM