using System.Collections; using UnityEngine; public class GunControl : MonoBehaviour { private InputSystem_Actions controls; [SerializeField] float gunShotDelay = 0.25f; private bool hasGunFired = false; private AudioSource gunshotSound; private void Awake() { controls = new InputSystem_Actions(); controls.Player.Attack.started += ctx => StartShot(); controls.Player.Attack.started += ctx => EndShot(); } void Start() { gunshotSound = GetComponent(); } private void OnEnable() { controls.Enable(); } private void OnDisable() { controls.Disable(); } void StartShot() { if (hasGunFired == false) { Debug.Log("Shot Fired"); StartCoroutine(FireTheGun()); } } void EndShot() { Debug.Log("Shot ended"); //count shots, reload } IEnumerator FireTheGun() { hasGunFired = true; gunshotSound.Play(); yield return new WaitForSeconds(gunShotDelay); hasGunFired = false; } }