2D Animation disables Player Controller Script
I'm creating a simple 2D PacMan style game, move the player around the maze, all good. I've added an "opening animation" to my character, and now he's frozen in place after the animation finishes, keyboard input no longer moves him. It seems like the animation has frozen it's transform, because when I disable the animation in Game mode, he moves again. I've added a "Done" state transition after the animation that has an empty clip, but didn't seem to help. Any help is appreciated, thx.
Answer by Judgeking · Apr 17, 2017 at 07:38 AM
In case anyone is interested, here's what I did.
Many people said to create a Parent gameobject and make my Player a child of it, and create the animation on the Parent object. That worked but seemed like a messy workaround.
What I did is just check the animator state (final state called ShipDone) and found 3 different methods. I created an animator parm called Done for the method I liked best.
private Animator anim;
void Start () {
anim = gameObject.GetComponent<Animator> ();
}
void FixedUpdate () {
/* Method 1
if (anim.GetCurrentAnimatorStateInfo (0).IsName ("ShipDone") && anim.enabled) {
anim.enabled = false;
}
*/
/* Method 2
if (anim.GetCurrentAnimatorStateInfo (0).IsName ("ShipDone") && anim.speed != 0) {
anim.speed = 0;
anim.Stop();
}
*/
/* Method 3 */
if (anim.GetCurrentAnimatorStateInfo (0).IsName ("ShipDone") && !anim.GetBool("Done")) {
anim.SetBool("Done", true);
anim.Stop();
}
}
Your answer
Follow this Question
Related Questions
Animation location problem! 0 Answers
How do I stop an animation from looping? 1 Answer
How do I make my attack trigger work? 1 Answer
Falling blocks skip animation while upside down 1 Answer
How do i extend a animation ? 1 Answer