Answer the question
In order to leave comments, you need to log in
What is the correct way to write this?
I'm wondering how to properly write wait until next shot?
After the shot, he must wait one second and again there is an opportunity to shoot, but how to write it correctly?
My decision:
private void Update()
{
if (Input.GetButtonDown("Fire1") && CanFire)
{
GameObject Bullet = Instantiate(BulletPrefab, FirePoint.position, transform.rotation);
Bullet.GetComponent<Rigidbody2D>().AddForce(transform.up * BulletSpeed);
CanFire = false;
Invoke("FireRateFunc", FireRate);
}
}
private void FireRateFunc()
{
CanFire = true;
}
Answer the question
In order to leave comments, you need to log in
IEnumerator ExecuteAfterTime(float timeInSec)
{
yield return new WaitForSeconds(timeInSec);
// do the right thing
}
I think you need this function
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question