I’ve made a few simple games so far, but I’m not sure how to manage sound and particles. What is an efficient and optimized way to manage the Sound and Particle? (Or general way)
[Sound]
(1) Attach an AudioSource component to every object and play it whenever sound is needed on that object.
(2) Create AudioSource GameObject equal to the number of Sounds and play as needed.
(3) Create a few(for multiple sound) AudioSources and use them while replacing the AudioClip.
(4) Other way?
[Particle]
(1) Attaching a Particle Component to an object that needs a particle.
(2) Create particles one by one and play whenever need them.
(3) Other way?
There’s no one-right-way to go about it, I’m afraid. The easy answer seems like all potential sources should get an AudioSource component, and then having sounds come from their source location (which is important in many games) becomes trivial. And while that seems obvious at first, some games don’t need even stereo sound. In thouse cases a single AudioSource with a couple helper scripts centralizes management and reduces resource usage. I know it’s not really a satisfying answer, but this is where design and experience tends to come in.
Particles have a similar response: For those objects constantly emitting (smoke, fire, etc), it makes sense for the particle system to be part of the GameObject at all times. For more temporary effects, I often have a library of emitters that I can instantiate at a given location, and then remove once the effect is complete.