unity while until code example
Example: unity how to make a delay untill you can shoot again
public Transform firePoint;
public GameObject bulletPrefab;
public float bulletForce;
public float fireRate = 0.5F;
private float nextFire = 1.5F;
private void Update()
{
if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Shoot();
}
}
void Shoot()
{
GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
Rigidbody rb = bullet.GetComponent<Rigidbody>();
rb.AddForce(firePoint.forward * bulletForce, ForceMode.Impulse);
}