x


How to get sound to play on barrel Explosion

can someone help me out with this plz. right now i got the barrel to explode but i cant seem to get my sound to play when the barrel explodes.

more ▼

asked Feb 24 '10 at 11:00 AM

Anoj gravatar image

Anoj
1 2 3 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You might want to use PlayClipAtPoint for this. It's great for one-off sound effects which can occur at an arbitrary position in your scene.

How you do this might depend on how you're detonating the barrel. If you have some function on your barrel which handles the explosion, you might do:

var explosionClip : AudioClip;

function Explode() {
   AudioSource.PlayClipAtPoint(explosionClip , transform.position);

   // (then whatever code generates the explosion)
   Destroy(gameObject);
}

You'd then need to make sure you drag in a reference to the audio clip, into the "explosionClip" variable in your barrel object (or prefab).

more ▼

answered Feb 24 '10 at 11:28 AM

duck gravatar image

duck ♦♦
40.9k 92 148 415

Hi thanks for getting back to me... theres a small issue here. I'm using the script from FPS tutorials "DamageReceiver.js" using that script i got the barrel to employed but after updating it with your scrip its still not playing the sound. I'm i doing something wrong.

Feb 24 '10 at 04:00 PM Anoj

Are you getting any errors when the sound is supposed to play? Did you put the line "AudioSource.Play...etc" into a function that is actually called, or did you just add the whole Explode() function? Did you drag the explosion sound audio clip into that variable in the inspector?

Feb 25 '10 at 10:42 AM duck ♦♦
(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:

x2483
x980
x522

asked: Feb 24 '10 at 11:00 AM

Seen: 1944 times

Last Updated: Feb 24 '10 at 04:01 PM