How can I play an animation with a script?
Hi guys, I'm a bit stuck on how to play an animation from a script, I can't find a good tutorial for this.
I'm trying to slide a panel in and out. I have an animator component on my panel. The first animation slides the panel in when it's active. This works great. But now I need to activate the second animation, but not sure how to reference it.
All my code is in a script attached to the GameController, not on the panel (which I'm calling "ScorePanel").
I thought this would work, but doesn't:
ScorePanel.GetComponent.<Animation>().Play(PanelSlideOut);
Answer by ARKMs · Nov 30, 2015 at 08:50 PM
You was very close: Firts you need get the component 'Animator' not the 'Animation'. Second when you use Play function need send a string of the name of animation want to play. In other words:
ScorePanel.GetComponent.<Animator>().Play("PanelSlideOut");
Works perfectly, thanks! I didn't use "Animator" originally because $$anonymous$$onoDevelop didn't highlight it, so I assume it was wouldn't work.