I’m making a gun script, and for an automatic gun the sound gets cut off when the sound is played again.
So, if I call source.Play();, how do I keep the sound, playing before, playing. So it doesn’t chop the sound off and play the new one?
Try AudioSource.PlayOneShot(). That creates a temporary GameObject/AudioSource w/ the specified clip and position, which you could also do yourself if you wanted more control over the sounds (though you probably don’t for a machine gun).
PlayOneShot is cool for its “easiness”, but it has drawbacks. It is totally “fire and forget”, meaning if you have 5 one shots playing on the same Audio Source, you cannot stop any one of them. You only can stop all of them. So I think it’s really only useful for very short sounds that would never need to be stopped.
Thank you ![]()