0

I am using a prefab with an audio source attached to it and is used only if you click on the prefab to play a short sound (click sound). There is a scene that I am using this prefab for ~50 times.

There is no problem at all, it works great but I was just wondering is it a bad practice to have so many prefabs each one using its own audio source?

Thank you.

Johny
  • 625
  • 2
  • 6
  • 26

1 Answers1

1

It depends on the use case, but in most cases you can't really avoid it(using more than one audio source). If you look at the inspector of the Audio Source-Component, you see a field for referencing the audio file. So basically even if you have 50 Audio Source-Components it just remains one audio file (in case that you only want to play this single sound). The intention of this approach with multiple audio sources is to get a "physically realistic" feeling. So as in real life if you are out of the range of an audio source you won't hear it.

For example if you have a game with around 50 enemies in the current scene, it's more or less necessary to attach each of them an Audio Source-Component because you want to hear only the enemies, which are in your range.

If you have just one central Audio Source it has to play everything and in most cases you have more work than benefit from it. But a static game like a card game can work very well with this approach, so that you have only one GameObject which holds an Audio Source-Component. If you have more than one sound effect, you have to change the referenced AudioClip programmatically every time you want to play a sound, which is not the currently selected one.

So basically its not really a bad practice, because in most cases it is more or less intended that you have more than one audio source.

MSauer
  • 158
  • 3