How do you cycle through animations through the use of c# code? Unity 3D

My zombie character will attack and walk towards the player when the player is close to it. However when the player is out of the zombie’s range it will keep attacking instead of doing an idle animation.

I know this doesn’t answer your question, but I think if you are trying to do animations, you should not be doing it through code.

This is something I’ve been looking into as well, and Unity already provides you the tool to perform animations without having to use code.

Another reason why you would want to avoid using code to animate your player (or any object) would be to reduce confusion with people on your team. Whether you are working solo or on a team, it’s generally good practice to have animations outside your code so others can work on it.

Here are some references you might want to look into:

  1. Mistakes made in Unity (1). Starts at the 28 sec mark
  2. How to animate in Unity (2)