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

Blink a mesh renderer 4 times

I am trying to blink my gameObject’s mesh renderer 4 times with a delay of 0.25 seconds. The mesh renderer gets disabled in the beginning but never re-enables and never blinks. I thought the best way would be to use a for loop.

    MeshRenderer mr;

    void Start () {
        mr = this.gameObject.GetComponent<MeshRenderer> ();
        StartCoroutine (Blink ());
    }

IEnumerator BlinkLid () {
       for (int i = 0; i < 4; i++) {
        mr.enabled = false;
        yield return new WaitForSeconds (0.25f);
        mr.enabled = true;
       }
    }

>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

You also need to wait before the next iteration!

IEnumerator BlinkLid () 
{
   for (int i = 0; i < 4; i++) 
   {
        mr.enabled = false;
        yield return new WaitForSeconds (0.25f); // or 0.125f if it shall take 0.25 in total
        mr.enabled = true;
        yield return new WaitForSeconds (0.25f); // or 0.125f if it shall take 0.25 in total
   }
}

otherwise you wait to set it to enabled = true but immeditely go to the next iteration where again you set it enabled = false 😉

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