How do I prevent audio from restarting if it's being asked to play again?

Basically I’m trying to add sound to my fully automatic M4. I have a sound file of a single shot from an M4 which I’m using. I made a script that tells the sound to play every few seconds as long as mouse button 1 is down. The problem is that instead of the sound playing out fully with the new one playing on top of it a few seconds later, the sound just restarts constantly without playing out fully. It works fine only if my weapon is semi auto with a RoF longer than the sound file, but my weapon has a high RoF. Here is the script:

#pragma strict
var gunSmoke : ParticleSystem;
var isFiring = false;

function Update () 
{
	if (Input.GetMouseButtonDown(0))
	{
		isFiring = true;	
		InvokeRepeating("ShotSound",0,0.3); //This also acts as RoF
		gunSmoke.Play();
	}
	if (Input.GetMouseButtonUp(0))
	{
		isFiring = false;
		CancelInvoke();
		gunSmoke.Stop();
	}
}

function ShotSound ()
{
	if (isFiring == true)
	{
		audio.Play();
	}
}

You could check if the audio is already playing

if (!audio.isPlaying)
    audio.Play();

i found this! watch the part of the video about PlayOneShot, it overlaps sounds if one is already playing instead of restarting them :smiley: