Periodic updates of an object in Unity

Posted by Blue on Game Development See other posts from Game Development or by Blue
Published on 2012-06-30T20:42:46Z Indexed on 2012/07/01 21:25 UTC
Read the original article Hit count: 260

Filed under:
|

I'm trying to make a collider appear every 1 second. But I can't get the code right. I tried enabling the collider in the Update function and putting a yield to make it update every second or so. But it's not working (it gives me an error: Update() cannot be a coroutine.)

How would I fix this? Would I need a timer system to toggle the collider?

var waitTime    : float = 1;
var trigger     : boolean = false;

function Update () {

        if(!trigger){
            collider.enabled = false;
            yield WaitForSeconds(waitTime);
        }
        if(trigger){
            collider.enabled = true;
            yield WaitForSeconds(waitTime);
        }
    }

}

© Game Development or respective owner

Related posts about unity

Related posts about timer