I’ve made something like a wheel of fortune. My problem is how I can optimize the spinning sound.
As the wheel spins, the indicator (I don’t know what it’s called. It looks like a triangle) hits the wheel’s spokes and make sounds. I used triggers to play one shot sound every time the indicator overlaps with one of the wheel’s sections. This works, but as the wheel spins, it creates a big amount of garbage. When the garbage collector kicks in, it freezes the game.
The other thing is making one sound file and looping it, but the wheel is physics-based. So that, the wheel doesn’t spin at the same speed every frame.
So the dirty little secret of PlayOneShot is that I think it creates a new GameObject with an AudioSource, plays the sound, then destroys that object. This creates garbage.
The solution is you need to make a pool of AudioSources (what’s the maximum number of these sounds you will play at once?) and play the sound on those sources in a round-robin fashion.