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