How do you change which animation to play in an object??

Very dumb question i know, but I just realized I don’t know how to do it and I can’t find any information on it anywhere. Also what is the difference between animationClip and animationState? What I want to do is change an enemy from “idle” to “attacking” when the player gets close enough.

An AnimationClip is the animation you would want to “play”. You can do this by:


when your distance check returns true.

That way you create a smooth transition from the playing animation to the requested animation.

animation.Play() is overloaded, and gives you options. If you do animation.Play(), it will play the current animation that is set to the instance of the animation class, which is animation.clip.


AnimationClip animClip1;
AnimationClip animClip2;

animation.clip = animClip1;
// this will play animClip1

animation.clip = animClip2;
// this will play animClip2;

Or you could pass in a string into Play, with the exact name of the AnimationClip: