I want to make a code run for a few seconds in if statement like I want to make BoxCollider.enabled=false whenever I press "e" and make BoxCollider.enabled=true again after a few seconds. How can I do this?
I tried the invoke method but it's not working.
if (Input.GetKeyDown("e"))
{
BoxCollider.enabled = false;
Invoke("enable", 2f);
}
void enable()
{
BoxCollider.enabled = true;
}