On / off code

I’m struggling with something basic, I can’t get my head around it.

Say I have:

	if(Input.GetKeyDown("2"))
	{
		doSomething = true;
	}

How can I code this so that when I press “2” again, it changes to false. Then vice versa, press “2” to switch on, then again to switch off.

Cheers.

Try :

doSomething = !doSomething;