Please help in triggering an animation through another object.

I have a button script and an “isPressed” boolean inside it. Also I have a camera animation. Who can help me with an if statement I will add to the button that will activate the camera animation when isPressed is true? Thanks in advance!

//Add in the body of the button script class
public GameObject camera;

void Update()
{
  if(isPressed)
  {
    camera.animation.Play("animation name");
  }
}

void OnGUI()
{
  if(GUI.button(args))
  {
    isPressed = true;
  }
  else
  {
    isPressed = false;
  }
}