- Home /
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.
Answer by duck · Feb 24, 2010 at 11:28 AM
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).
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.
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?