I created a caroutine, and i want it to run in every x seconds. i tried using while loop but it didn't worked for this caroutine. can anybody please help ? thanks.
IEnumerator StartFire()
{
{
Firing = true;
animator.SetBool("isFiring", true);
yield return new WaitForSeconds(2);
Firing = false;
animator.SetBool("isFiring", false);
}
}
CodePudding user response:
I think you would be better off using InvokeRepeating()
. You only need to call it once and it will repeat.
Example:
void Start()
{
InvokeRepeating("myTask", 1.5f, 1.5f);
}
void myTask()
{
// Do something.
}
If you want to stop it at any point you simply have to call: CancelInvoke();
.