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
  • 1
    \$\begingroup\$ I would probably go with a singleton type audio manager and use events \$\endgroup\$
    – Savlon
    Commented Feb 13, 2017 at 2:56

1 Answer 1

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\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .