Hello there!! So when i hold LMB its continuously makes the gun noise but i want it so that there a 2 second delay in between each gun sound, how do i do this??

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

 public class GunShot : MonoBehaviour
 {

      public AudioSource someSound;

   


         void Update()
        {
              if(Input.GetButton("Fire1"))
              {
                    someSound.Play();
              }
        }
},using System.Collections;

using System.Collections.Generic;
using UnityEngine;

public class GunShot : MonoBehaviour
{

public AudioSource someSound;
// Start is called before the first frame update
void Start()
{
    
}

// Update is called once per frame
void Update()
{
    if(Input.GetButton("Fire1"))
    {
        
        someSound.Play();
    }
}

}

It’s pretty simple, actually. You could just use a recursive co-routine to achieve this.
And, we will also use a boolean to check if the button is being pressed or not.

So your updated script would look like this :

public class GunShot : MonoBehaviour {

 public AudioSource someSound;
private bool isButtonPressed = false;
 // Start is called before the first frame update
 void Start()
 {
     
 }
 // Update is called once per frame
 void Update()
 {
     if(Input.GetButton("Fire1"))
     {
         // Check if we are already playing the gunsound...
            if (isButtonPressed == false)
            {
                isButtonPressed = true;
                StartCoroutine(PlayGunSound());
            }
         }
         else
        {
            isButtonPressed = false;
        }
     }
 }

IEnumerator PlayGunSound()
    {
        someSound.Play();
        // wait for 2 seconds
        yield return new WaitForSeconds(2f);
        // Play the gunshot sound again if the button is still being pressed
        if (isButtonPressed)
        {
            StartCoroutine(PlayGunSound());
        }
        else
        {
            // Do nothing !
         }
    }
}

Let me know how it turns out for you :slight_smile: