Search Unity

Making a Flickering Light Without Yield WaitForSeconds

Discussion in 'Scripting' started by PirateMonkey, Jul 23, 2014.

  1. PirateMonkey

    PirateMonkey

    Joined:
    Jun 24, 2014
    Posts:
    28
    So I am trying to create a script that explodes a missile OnCollisionEnter2D. So far I have this script:

    1. var delay :float=2;
    2. functionOnCollisionEnter2D()
    3. {
    4. light.enabled =true;
    5. rigidbody2D.velocity =Vector2(0,0);
    6. animator.SetBool("missileCollision",true);
    7. yieldWaitForSeconds(delay);
    8. Destroy(gameObject);
    9. }
    Now I want to add a flickering light effect. The problem is that I can only figure out how to do it using 'yield WaitForSeconds' (http://forum.unity3d.com/threads/flickering-light.4988/). This causes further delay to the Destroy(gameObject) due to there being multiple 'yield WaitForSeconds' statements, which I do not want. Is there another way to accomplish this??
     
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
  3. PirateMonkey

    PirateMonkey

    Joined:
    Jun 24, 2014
    Posts:
    28
    Awesome, didn't know what those were before now. Thanks for the tip!