title: My sound keeps repeating in Unity whenever I press the left mouse button instead of playing once
body: <p>I am working on an FPS game in Unity using C#. This code is supposed to play a sound once whenever you press the left mouse button, but whenever I press it the sound plays repeatedly with no break between the sounds. I did find a question very similar to this one but I couldn't implement the answer into my code, Link: <a href="https://forum.unity.com/threads/how-to-play-a-sound-with-c.206152/" rel="nofollow noreferrer">https://forum.unity.com/threads/how-to-play-a-sound-with-c.206152/</a>. Any help will be appreciated.</p>
  
  <pre><code>    using UnityEngine;
  
      public class GunFire : MonoBehaviour
      {
          void Update()
          {
              if (Input.GetButton("Fire1"))
              {
                  AudioSource sound = gameObject.GetComponent&lt;AudioSource&gt;();
                  sound.Play();
              }
          }
      }
  </code></pre>