Enabling and Disabling Colliders 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/06/30 21:26 UTC
Read the original article Hit count: 174

Filed under:
|

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

How would I fix this? Would I need a timer system and set the collider to be enabled every 'x' seconds and disabled every 'y' seconds?

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