1
\$\begingroup\$

If I Play the gun sound on my "bullet" object, how can I prevent the end of Audio sound if the bullet hit something so it destroy. To clarify:

Bullet prefab -> Audio Source -> Audio Clip = MachineGun.mp3 PlayOnAwake = true

When I instantiate bullet, MachineGun AudioClip is played. But the bullet is fast and hit something before the clip is end. This Kill the machine audio effect making it irrealistic.

How can I tell Unity "Play the sound to the end, despite the object is destroyed".

I've tried

Destroy(gameObject, AudioClip.length)

But it seems not works

\$\endgroup\$
  • 1
    \$\begingroup\$ I would probably go with a singleton type audio manager and use events \$\endgroup\$ – Savlon Feb 13 '17 at 2:56
1
\$\begingroup\$

One option is to use AudioSource.PlayClipAtPoint(), this will create a new audiosource for the clip at the given position and then automatically clean up after the playback is complete.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.