I am making a card game where it plays a sound effect when a card is added to a pile, but during the setup cards are rapidly added to different piles and it breaks if I use a single Audiosource
If I play it from a single audiosource it seems not to play them all or if it is it’s playing them all at once.
vs
If I do it by having an audiosource on each pile and use that instance of it and hear the different effects played.
I am in the middle of rewriting the game as the first time was a dry run and didn’t know what I was going to need and is a bit rough and came across this while trying to streamline the in game audio by having a GameAudioManager singleton to handle the audio.
Is there a reason for this and a solution?
Info
Sound Effect is a MP3 and 3kb
Delay between effects is 0.01f
Each AudioSource can only play 1 sound at any given time. You will need a separate audio source for each sound that can play at any 1 time, even for multiple copies of the same sound. Your two best options are:
Create a new AudioSource every time you want to start a sound, and delete it when the sound completes. You can either Instantiate a prefab with an AudioSource attached, or you can create a new GameObject() and use newGameObject.AddComponent<AudioSource>(). You’ll have to write a script that deletes the object when it’s done playing.
Create a list of AudioSources large enough to play as many sounds as you think you will need at any one time. Any time you want to play a sound, you use the next AudioSource in the list, and restart at the first AudioSource once you’ve gone through the whole list.