How to toggle a boolean on and off on mouse input ?

I made this script:

private var onoff : boolean = false;

function Update (){

	if(Input.GetButtonDown ("Fire1")){
	
		onoff = true;
		print("left");
		
		}
		
		if (Input.GetButtonDown("Fire1") && onoff == true){
		
		onoff = false;
		print("right");
		
		}

}

but I don’t know why isn’t working, I want it to toggle on and off something.

how can I achieve this ?

There’s a much easier way to do that:

private var onoff : boolean = false;

function Update (){

    if(Input.GetButtonDown ("Fire1")){
        onoff = !onoff; // toggles onoff at each click
    
        if (onoff){
            print("left");
        } else {
            print("right");
        }
    }
}