How do I animate a 2D sprite?

I imported a spritesheet, of a walk animation. I used the sprite editor to slice it. Then, I dragged the animation into the scene, and when I hit play, it animated it, perfectly fine. So, I looked at the properties of the thing I dragged into the scene. Under the Animator component, there was a property called Controller. In the scene, when I changed it to a different animation, and hit play, it switched the animation. The problem is, I can’t seem to do that in script. How could I change the Controller in JavaScript?

For one character, you should create different Animation Clips (running / walking / idle / etc.) that are all controlled by 1 Animator Controller.

Then you change the Animation Clips by changing the conditions (Parameters) by using methods like

// etc.

A basic understanding of Mechanim (Unity’s Animator Controller mechanism) is highly recommended.