is there a way to reduce overlaping sounds from a multi spawned prefab that uses a audio source?
if i spawn more of those prefabs i have to much sounds of it running at once. and i want to reduce them to 2 instead of hearing them all. 8 times the same sound is sure to much for my iphone app and they are looping too. xD
asked Aug 02 '10 at 03:13 PM
One easy solution would be to have a simple central (e.g. Singleton) sound manager that controls playing those sounds. You'd notify that sound manager whenever a prefab is instantiated and then the sound manager could decide whether or not to play the spawning sound.
Obviously, you'd have to switch "Play on Awake" off (personally, I never use this because I prefer to have more control).
Then, in your sound manager, get a reference to the AudioSource of the object that was just instantiated, and use Play() to start playing the sound. You might keep references to the objects playing sounds and check if there's already too many playing already. One way of doing so is isPlaying (you might also check for null references in case those objects might already have been destroyed ... so be a little careful there).
That should give you a good start.