audio distortion when key is pressed

First off i wish to thank all the responders for all the help i have recieved from the forums members with my questions. I have a problem with my sound setup. When i press a key to rotate my turret on my model the sound plays but is distorted. I have to hold down the key to turn the turret I have some good sounds for this action but they sound horrible. Can someone help me with this?

here is the script i have been using.

function Update () {

if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S)) {

audio.Play();

} else {

audio.Stop();

}

}

thanks

wayne

Play restarts the sound each time it’s called. Since in the function above it will happen all Updates while the keys are pressed, you will have a horrible sound, for sure. You can avoid this by checking if the sound ended before calling Play():

function Update () {
  if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S)) {
    // only call Play if the audio has ended
    if (!audio.isPlaying) audio.Play();
  } else {
    audio.Stop();
  }
}