UI Button ON/Off

I am using the UI canvas, How do I get the object(monster) to turn off using the same button.

public class monsterSwitch : MonoBehaviour {


	public GameObject monster;
		
	public void changeMonsterOn (string changeToOn) {
	
	
	monster.SetActive(true);
	}


	public void changeMonsterOff (string changeToOff) {
		
		
		monster.SetActive(false);
	}

}

private bool toggle =false ;

public void changeMonsterOn () 
{
     
     if(!toggle)
{
     monster.SetActive(true);
toggle= true;

}
else 
{
   monster.SetActive(false);
toggle= false;
}
     }

Hope this will work if you just want to toggle with the UI button

Easiest way is this

 private bool toggle = false; // global variable default is off
 
 public void changeMonsterOn () 
 {
 toggle = !toggle; // if toggle is false then it would be true, if toggle is true then it would be false like on and off
monster.SetActive(toggle); // pass the toggle value
}

Also this works, but if needed, remember to put start value

if(value)
{
        value = false;
        return;
}

if(!value)
{
        value = true;
        return;
}