I want to make it so that everytime i shoot my gun, the gunshot audio is playing.
But when i click the button that shoots the gun and hold it, it duplicates so many times.
I want to set a delay on each gunshot sound effect but i dont know how.
Any pointers?
Code:
using UnityEngine;
public class CharacterShooting : MonoBehaviour {
public Gun gun;
public int shootButton;
public KeyCode reloadKey;
public AudioClip shot;
AudioSource audioSource;
void Start() {
audioSource = GetComponent<AudioSource>();
}
void Update() {
if(Input.GetMouseButton(shootButton)) {
gun.Shoot();
audioSource.PlayOneShot(shot, 0.7F);
}
}
}