Simply Play a 2D animation

Before someone says to google it, I have been searching for an hour now. I want to trigger an animation through code and not through the animator component bubbles

I am working on a 2D platformer and all I need is to play a animation in code. With 3D animation it is really easy. Your make the animation, convert it to legacy and

GetComponent(Animation).Play("ThingYouWantToPlay");

I have been searching for a few hours and all the documentation I can find on 2D animation is with the animator component and you need to set up the animator bubbles and set an idle animation ect. I don’t want to do this because I am working on a project that doesn’t have the normal physics of a typical platformer and my player will sometimes be walking on walls or around a small planet.

The code:

private var direction : boolean = false;
private var isWalking : boolean = false;

function Update(){
   if(Input.GetKeyDown(KeyCode.D)){
       //Play the walkingRight animation and loop it
       isWalking == true;
       direction == false;
   }
   if(Input.GetKeyUp(KeyCode.D)){
       //Stop the walkingRight animation
   }
   if(Input.GetKeyDown(KeyCode.A)){
       //Play the walkingLeft animation and loop it
       isWalking == true;
       direction == true;
   }
   if(Input.GetKeyUp(KeyCode.A)){
       //Stop the walkingLeft animation
   }

   if(isWalking == false && direction == false){
       //Play the looking right idle animation
   }
   if(isWalking == false && direction == true){
       //Play the looking left idle animation
   }



}

If anyone could guide me in the right direction that would be awesome!

EDIT :
Response to Graham Dunnet : http://johnstejskal.com/wp/wp-content/uploads/2014/09/feature.png
The reason that the tutorials don’t help me is because it uses the new animation state system and i don’t need something this complex. All I want to do is play an animation via code.

For me the following worked the best:

  • Add an Animation to an object

  • Remove AnimationController

  • Go to Debugmode in Inspector

  • Check Animation as Legacy

  • Via code you just get the Animation component

    GetComponent().Play();

    //or

    GetComponent().Play(“desired Animation”);

for me the best solution right now

Edit:

doesn’t seem to show the Code properly, you have to add the Class ‘Animation’ …