How can i reverse all the booleans in a method?

ok im not really sure how to ask this but maybe someone can help.

I would like to reduce one of these blocks of code …

  void NotPressed ()
    {
        for (int i = 0; i < DangerousObjects.Count; i++)
        {
            isGroundButtonPressed = false;
            DangerousObjects*.SetActive(true);*

animator.SetBool(“GroundButtonOn”, false);
}
}
void Pressed()
{
for (int i = 0; i < DangerousObjects.Count; i++)
{
isGroundButtonPressed = true;
DangerousObjects*.SetActive(false);*
animator.SetBool(“GroundButtonOn”, true);
}
}
so it can be something like this

void NotPressed ()
{
!Pressed();
}
void Pressed(bool isPressed)
{
for (int i = 0; i < DangerousObjects.Count; i++)
{
isGroundButtonPressed = true;
DangerousObjects*.SetActive(false);*
animator.SetBool(“GroundButtonOn”, true);
}
}
that doesnt work^ but im looking to do something like that.i dont need to do this – i just want to know how someone one would go about doing that? is there a way i can flip all the boolean values to it’s opposite value?

Hi @spencerz , I think you can try this

 void NotPressed ()
     {
        SetProperty(false)
     }
     void Pressed()
     {       
        SetProperty(true);
     }  

 void SetProperty (bool value)
     {
         for (int i = 0; i < DangerousObjects.Count; i++)
         {
             isGroundButtonPressed = value;
             DangerousObjects*.SetActive(!value);*

animator.SetBool(“GroundButtonOn”, value);
}
}

To invert a bool you can use the ! operator so

MyVariable = !MyVariable

Will flip it from what ever value it was to the alternative value.