Audio playing problem

Hello guys! My player movement script is almost done, just going to add the audio depending on movement. I have the resources already, but I can’t figure out how to play them normally. Can somebody suggest what I should be using? Here is a part of my script:

function Update ()
{
   if(Input.GetKey(KeyCode.W))
       audio1.play();
}

I’m guessing it’s because it starts the audio in every frame because of Update, causing the audio to be stuck in the first second. So, how do I fix this? Thank you in advance.

You can use the audio source’s ‘isPlaying’ variable to see if the clip is already playing, that way you can preventing it from starting again.

if(Input.GetKey(KeyCode.W))
{
   if(audio1.isPlaying == false)
      audio1.Play();
}