I wanna disable a 2D box collider for a certain amount of time… let’s say 3 seconds, after those three seconds I would like it to enable itself again automatically.
the only way I can wrap my head around this is by using triggers,
and like setting it to true or false after a certain amount of time.
how would I be able to do this?
Oh and other ways of doing something like this is totally welcome!,
public float time = 3f;
private void Awake()
boxCollider2D.isTrigger = true;
yield return new WaitForSeconds(time);
boxCollider2D.isTrigger = false;
just wanna share this other method of doing cooldown related stuff since you mention you’re interested in alternate answers – this potentially lets you rapidly reset the time toward re-enabling the collider without having to cancel out the coroutine, which can be a pain depending on what youre doing with it. this version is good for snappy attack interactions and the like.
float cooldown = 3f; //or whatever amount of time you want the colldier off for.
// call this function whenever you want to turn the collider off.
collider.isTrigger = false;
collideroff = true;
enabletime = Time.time + cooldown;
if(collideroff && Time.time > enabletime)
collider.isTrigger = true;
collideroff = false;