Accessing Animator Component from tagged objects in an Array in Start and then triggering its bool in Update

I want to get the Animator component for each object in my scene tagged “Legs” in the Start Function, and then in the Update function I would like to set the bool “isWalking” from that animator to either true or false based on “if statements”.
.
So far I have:

public GameObject[] legs;
Animator anim;

// Start is called before the first frame update
void Start()
{
    legs = GameObject.FindGameObjectsWithTag("Legs");
    foreach (GameObject obj in legs)
    {
        anim = obj.GetComponent<Animator>();
        anim.SetBool("isWalking", false);
    }

This successfully creates an array with all game objects tagged “Legs”, retrieves their Animator Component which I’ve called ‘anim’, and sets the “isWalking” bool to false.
.
THE PROBLEM is that I seem to only be able to change the Animator’s “isWalking” bool when the code is inside the foreach brackets. I need to be able to change it in the Update Function, inside an ‘if statement’.
.
Any help would be huuuuuuge and I’d be super grateful

Note that your animator instance is being overriden for each leg. You could use an array of animators, instead.

Other possible solutions:

  1. Assuming the GameObject’s array of legs would be fixed during the entire scene: save them as an attribute: in the start() method: legs = GameObject.FindGameObjectsWithTag(“legs”). In update, travel across all legs, get its animator and perform the actions that you want.
  2. If the Legs array would be different during the scene, you would need to find all the legs objects in each frame, so you can repeat your current code in the Update() method.
  3. (To speed up method 2 Idea) You could save all the legs objects in an array, and control the addition/substraction in that array as the legs objects are appearing or disappearing in the Scene.