For a 2d game. I have a block that has a child object which I’d like to animate whenever a certain action occurs. I set up the animation in the Animation window, and I can see it working properly. I hit play and I can see it running over and over again in Preview mode. This animation only happens per run to the block, so I don’t need all that unnecessary transition stuff. I make the animation Legacy, and when I try to fire the animate call I see nothing. I get no errors. Here’s the code trying to run the animation:
Debug.Log(this.gameObject.transform.GetChild(0));
try {
Animation a = this.gameObject.transform.GetChild(0).GetComponent<Animation>();
if (a != null) {
a.Play("falling_dots", PlayMode.StopAll);
Debug.Log("Playing falling_dots");
}
} catch (UnityException ue) {
Debug.Log(ue.ToString());
}
The image shows my object’s hierarchy. At the top floating_block_animated is the parent object and falling_dots is the child. The Inspector is showing the child
Lastly, if there’s a better way to do this I’m open to suggestions.