How would I detect if key get pressed 2 times

Hi, I have a variable which grants the player access to place objects. Now, if I for example press B, it should grant access to the player to place objects, and if I press B again it should remove access, and so on so forth. What’s the best way to do this?

Just use a bool, and then toggle it.

bool grantAccess = false;

if (Input.GetKeyDown(KeyCode.B))
   grantAccess = !grantAccess;

// somewhere else
if (grantAccess)
   placeObjects();