Time for action - animation interrupts

The trouble is that we're telling the character to play his "catch" animation, but it's not happening. We see, at best, the first frame of that animation, and then it's interrupted by either the "idle" or "step" animation.

Luckily, we can add a condition to the script to prevent these glory-hog animations from playing if we're trying to catch a beer stein. Dip back into your CharacterScript and make these changes:

if(lastX != transform.position.x) {
if(!isMoving) {
isMoving = true;
if(!animation.IsPlaying("catch")){
animation.Play("step");
}
}
}
else {
if(isMoving) {
isMoving = false;
if(!animation.IsPlaying("catch")) {
animation.Play("idle");
}
}
}

By wrapping the animation.Play calls in these animation.isPlaying ...

Get Unity 3D Game Development by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.