Two If statements in Update

I want to disable axe collider when e is pressed and enable it again when e is pressed again. I have the bool “axeOnHand” so If statements can be called when needed. But when i press e, both If statements are called. I think the problem is they are called in the same frame. But i don’t know how to solve this issue.

if (Input.GetKeyDown("e") && axeOnHand)
        {
            Debug.Log("axe released");
            axe.GetComponent<BoxCollider>().enabled = !axe.GetComponent<BoxCollider>().enabled;
            axeOnHand = false;
        }
        if (Input.GetKeyDown("e") && axeCollided && !axeOnHand)
        {
            axe.GetComponent<BoxCollider>().enabled = !axe.GetComponent<BoxCollider>().enabled;
            axeOnHand = true;
            Debug.Log("axe picked");
            pickUpAxe();
        }

You could be correct assuming axeCollided is true.

In that case, the first one fires, axeOnHand becomes false, so the second one fires also.

It might be fixable if you simply put the second if() statement inside an else block, something like:

if (...)
{
  ...
}
else
{
   if (...)
   {
     ...
   }
}
if (Input.GetKeyDown("e") && axeOnHand)
        {
            Debug.Log("axe released");
            axe.GetComponent<BoxCollider>().enabled = !axe.GetComponent<BoxCollider>().enabled;
            axeOnHand = false;
        }
       else if (Input.GetKeyDown("e") && !axeOnHand)
        {
            axe.GetComponent<BoxCollider>().enabled = !axe.GetComponent<BoxCollider>().enabled;
            axeOnHand = true;
            Debug.Log("axe picked");
            pickUpAxe();
        }

thank you, it works

Multiple if statements are completely independent of each other and all will be evaluated, in order, so changing variables in one can have an effect on later ones. An if/else is a single block and only one (or none) of its options will evaluate to true.