- Home /
How to animate child game objects with a script according to animator's state?
Hi I want to make a set of scripts that I can reuse multiple times that can animate game objects based on different states:
Prefab A -> Parent (with animator) -> Child A | Child B | Child C
Prefab B -> Parent (with animator) -> Child A | Child B | Child C | Child D
All children animate exactly the same way, except in different directions, which I set in the inspector, using MoveScript.cs This script has methods to set start position, end position, and start time variables.
In the Update() of MoveScript.cs, if a bool IsMoving is true, it will Lerp from begin to end positions. Those methods are called from two behavior scripts Enter.cs and Exit.cs, called at the beginning of the animation states: Enter and Exit.
It animates one perfectly, but none of the others. I think I'm going to have to make a script for the Parent object that finds it's children, and activates some methods in the children based on the states. But I'm not sure how to do that, nor if this is the best way to go about it.
Your answer
Follow this Question
Related Questions
Why I have a 'lag' between parent and child ? 0 Answers
Can the animation editor create local rotational data? 3 Answers
Character picking up box 0 Answers
Adding animation clips via script 2 Answers
Model children is at the wrong place within the animation 0 Answers