- Home /
How to apply Animator to different game objects (when animations affect children)
Is there a way to drill down from Animator
to the game objects that get animated within each state?
In my case I have a keypad of identical buttons. As you see below each number pad has PadCircle and PadText children:
Here is the state machine for the animator applied to Pad_0.
At present, each animation state affects the colour of the two children. (In future it could affect other properties such as scale too.)
I want to be able to apply this animator to each of the other buttons. I figured that I could create a script that gets the children and binds them to the animations during Awake()
. Is this possible? Or is there another way to apply an animation state machine to a complex game object like this?
Answer by paul-masri-stone · Sep 20, 2021 at 11:27 AM
I found a solution: make the button a prefab. Then the keypad is made up of prefab instances and Unity magic handles all the rebindings.
(I still wouldn't know how to access individual game object properties within animation states starting with the Animator
and I'm curious how to do that, but I no longer need a solution for my immediate problem.)