i am attempting to implement a gunshot sound to go alongside a gun firing and animation, the gunshot sound is slightly longer than the time it takes for me to fire the gun again; i am asking if and how it would be possible for me to use the sound multiple times without cutting off the first sound with the second.
code if it matters:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pistolFire : MonoBehaviour
{
public GameObject blackPistol;
public bool isFiring = false;
public GameObject muzzleFlash;
public AudioSource pistolShot;
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
if (isFiring == false)
{
StartCoroutine(firePistol());
}
}
}
IEnumerator firePistol() {
isFiring = true;
blackPistol.GetComponent<Animator>().Play("firePistol");
pistolShot.Play();
muzzleFlash.SetActive(true);
yield return new WaitForSeconds(0.015f);
muzzleFlash.SetActive(false);
yield return new WaitForSeconds(0.13f);
blackPistol.GetComponent<Animator>().Play("New State");
isFiring = false;
}
}