C# to set trigger on animator components of all children

I know this is probably simple. Can someone give me some C# example code for how to do the following:

I have a game object acting as a container for two cubes (call it “Parent”). Each of the cubes has an animator component on it, each using the same animator controller. That controller uses the parameter “AnimateNowParam” to transition from one state to another. I have the following script on Parent. But it doesn’t cause both cubes to changes animation states. It only causes the first cube to change animation states. How do I get it to cause both cubes to change states?

using UnityEngine;
using System.Collections;

public class AnimateNow : MonoBehaviour
{
	Animator anim;
	int buttonHash = Animator.StringToHash("AnimateNowParam");

	void Start ()
	{
		anim = GetComponentInChildren<Animator>();
	}

	public void AnimateNowFunction()
	{
		anim.SetTrigger (buttonHash);
	}
}

GetComponentsInChildren is what you want: Unity - Scripting API: Component.GetComponentsInChildren

This will return an array that you can either iterate over with a for loop or use forEach with a delegate method.

I’ve not ran this but it should be close:

 using UnityEngine;
 using System.Collections;
 
 public class AnimateNow : MonoBehaviour
 {
     Animator[] anims;
     int buttonHash = Animator.StringToHash("AnimateNowParam");
 
     void Start ()
     {
         anims = GetComponentsInChildren<Animator>();
     }
 
     public void AnimateNowFunction()
     {
         foreach (Animator anim in anims ) 
            {
              anim.SetTrigger (buttonHash);        
            }
      }

I tried your code and it doesn’t work. If you have any ideas. But thank you so much for helping me!