I'm currently trying to build a game that requires the character to pick up some items and I want a sound to play when an item is picked up.
below is the code that I have so far
now the problem that I am facing is that the sound just stops because the item is destroy and I don't really want to yield it for a second.
Is there any way that I can attach the sound to an empty gameobject and make that play instead when my character collides with the item ? or is there any way else to code this ?
This sounds like an ideal situation to use AudioSource.PlayClipAtPoint.
This function does exactly what you want automatically - it creates a new audio source at the position specified, and cleans up the audio source afterwards, making it a "fire and forget" style function.
To use it in your script, you'd change the code to something like this:
answered May 22 '10 at 12:15 PM
I am having the same issue, but my problem is the camera is far from the player and I tweak my AudioSource ramp for each sounds. But with this, I have no choice to use the default setting..
answered Apr 05 '12 at 10:55 PM