Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i make my caroutine run in every x seconds

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);

    }


}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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();.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading