I have a gun in my game, and I want a gun shot to be played when a bullet is shot. This is the code:
void Awake()
{
FindObjectOfType<AudioManager>().Play("bulletShot");
}
However, whenever a gun with a high fire rate is shooting, you can’t hear the sound because it just keeps restarting the audio source instead of playing a new one. Thanks in advance!
An AudioSource can only play one thing at a time.
You could just make an array of AudioSources that you rotate through (round robin) so there’s always one available to play.
1 Like
So you are saying to have multiple of the same audio source in an array, and just loop though that? Are you sure that is the simplest way to do it, as that seems quite unnecessary. Of coarse, if that’s the only way I will do just that.
use AudioSource.PlayOneShot();
it does not cancel the clips that are already playing.
1 Like
Nope.
But it’s what I would try because it could be implemented in less time than it took me to type this message and the previous one.
This also works as long as you’re not using positional audio, eg, don’t care where the sound comes from in space, such as wanting it to come from a gun muzzle.
1 Like
Thanks; this works just as intended.