I want to add shoot cooldown to my single shot gun
how do i do it
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using TMPro;
public class SingleShotGun : MonoBehaviour
{
public TMP_Text hitText;
public float damage = 10f;
public float range = 100f;
bool shot;
public Camera fpsCam;
public GameObject hitmarker;
public float shotsFired;
public float shotsHit;
void Start()
{
shot = false;
}
// Update is called once per frame
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
SingleShotShoot();
}
if(shot)
{
StartCoroutine("hitmarkerShow");
}
hitText.text = shotsHit + "/" + shotsFired;
}
void SingleShotShoot()
{
shotsFired += 1;
RaycastHit hit;
if(Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
shot = true;
shotsHit += 1;
}
}
IEnumerator hitmarkerShow()
{
hitmarker.SetActive(true);
yield return new WaitForSeconds(0.05f);
hitmarker.SetActive(false);
shot = false;
}
}
help