Heya…
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!,
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.
BoxCollider2D collider;
float enabletime;
float cooldown = 3f; //or whatever amount of time you want the colldier off for.
bool collideroff;
// call this function whenever you want to turn the collider off.
void TurnOffCollider()
{
collider.isTrigger = false;
collideroff = true;
enabletime = Time.time + cooldown;
}
void Update()
{
if(collideroff && Time.time > enabletime)
{
collider.isTrigger = true;
collideroff = false;
}
}