Sputtering Audio

Newbie question.

I am working on a space game where the character is a spaceship. When the player presses the accelerator button, the ship accelerates, fire and smoke come out of the engine, and an audio file is played for the engine sound.

Although, I am guessing there is a better way to do this, I enable/disable the engine sound by using GetComponent(AudioSource).enable, as shown below. This seems to be causing a really bad sputtering of the audio file. I’m not sure if it is constantly restarting the file or its playback is just really choppy.

Does anyone know why this is occurring, how to fix, or a better way to get the intended effect? Thanks.

var spaceFighter : GameObject;
var forwardForce = 1000;
private var drag = 2;
static var engineSound = false;

function Start () {

}

function OnGUI() {

var engineFire = GameObject.FindGameObjectsWithTag("engineFire");
var engineGlow = GameObject.FindGameObjectsWithTag("engineGlow");
var engineLightSource = GameObject.FindGameObjectsWithTag("engineLightSource");
var engineSmoke = GameObject.FindGameObjectsWithTag("engineSmoke");
var engineSparks = GameObject.FindGameObjectsWithTag("engineSparks");
var engineSound = GameObject.FindGameObjectsWithTag("engine");

		if (GUI.RepeatButton(Rect(Screen.width*0.88,Screen.width*0.48,Screen.width*0.1,Screen.width*0.1),"Accelerate")){
			spaceFighter.rigidbody.AddRelativeForce(Vector3.forward * forwardForce);
			
				for(var i in engineFire){
				i.GetComponent(ParticleRenderer).enabled = true;
				}
				
				for(var i in engineGlow){
				i.GetComponent(ParticleRenderer).enabled = true;
				}
				
				for(var i in engineLightSource){
				i.GetComponent(Light).enabled = true;
				}
				
				for(var i in engineSparks){
				i.GetComponent(ParticleRenderer).enabled = true;
				}
				
				for(var i in engineSmoke){
				i.GetComponent(ParticleRenderer).enabled = true;
				}
				
				for(var i in engineSound){
				i.GetComponent(AudioSource).enabled = true;
				}
			}
			else
			{
     		
	     		for(var i in engineFire){
				i.GetComponent(ParticleRenderer).enabled = false;
				}
			
				for(var i in engineGlow){
				i.GetComponent(ParticleRenderer).enabled = false;
				}
				
				for(var i in engineLightSource){
				i.GetComponent(Light).enabled = false;
				}
				
				for(var i in engineSparks){
				i.GetComponent(ParticleRenderer).enabled = false;
				}
				
				for(var i in engineSmoke){
				i.GetComponent(ParticleRenderer).enabled = false;
				}
				
				for(var i in engineSound){
				i.GetComponent(AudioSource).enabled = false;
				}
			}
			
			
		if (GUI.RepeatButton(Rect(Screen.width*0.02,Screen.width*0.48,Screen.width*0.1,Screen.width*0.1),"Break")){
			Debug.Log("Clicked the button with text");
			spaceFighter.rigidbody.drag = drag;
			}
			else
			{
			spaceFighter.rigidbody.drag = 0;
			}
	}

Sorry - realized I should post to Unity Answers, not Forum.

What happens if you check to see whether it is disabled before enabling it?

You might want to use Pause/Play or Stop/Play depending on the effect you want.