In my game I’m firing blobs of paint from a gun.
The paint blobs are simply particles that send a collision message once they hit something.
The trouble is that I need to play a “splat!” sound from wherever the particle collides.
As they’re particles I can’t attach an audioSource, and adding an audioSource to the object it collides with (the ground) will play from the centre of the ground rather than the specific location the particle collides with it.
I’ve though of two ways to do this:
- Instantiate a GameObject with an audioSource at the point of impact to play the sound, then delete itself.
- Have a few GameObjects with audioSources in the scene and have them move to the impact point when needed to play a sound.
Method 1 seems like it will be an expensive method, especially with a lot of particles going on.
Method 2 seems like it would be a nightmare to manage.
I may be overcomplicating things. Does anyone know of a better way to accomplish this?
It seems like it should be an easy thing to do but searching has yielded no results.
Thanks in advance!
You can also use AudioSource.PlayClipAtPoint ( Unity - Scripting API: AudioSource.PlayClipAtPoint ) which basically does most of the heavy lifting for you.
I do not know if Unity does clever reuse of audio source objects under the hood though, but I’d recommend doing this first and seeing what the performance is like.