Make a boolean positive and then negative with same button

Hey all
So I’ve looked a bit and haven’t really found an answer, so here goes.
I have a code ( in JS but help in C# works also)
that starts an animation when the space key is pressed and I have that part working but I don’t know how to make it so that when I press the space key again the animation will stop.

this is the relevant code

private var anim: Animator;		//a reference to the animator component

function Awake()
{	
	//set up references
	anim = GetComponent(Animator);
}

function Update()
{
var swing: boolean = Input.GetButton("Attack");
	
	//Animate the player
	Animating(swing);
}
function Animating (swing: boolean)
{
		
	if(swing == true)
	{
		anim.SetBool("Sword01", true);
	}
								
}

So yeah any help on how to make it set the boolean back to false by pressing the space button a second time would be awesome! The animator is already set up so when the boolean turns false the animation should stop.
Thanks

function Update()
{
if (Input.GetButtonDown(“Attack”))
{
anim.SetBool(“Sword01”, !anim.GetBool(“Sword01”));
}
}