Change sprite to animation in unity 5 2d (c#)

I want to do the same as this older post with one change:

Change the sprite of a Object in Unity

I want to use a .anim animation (created with unity) after the space key is pressed instead of another sprite. The problem is I can't drag the animation file to the sprite slot in the script component.

Thanks.

• What is your desired effect? Are you just looking to transition from one animation to another? – Savlon Jul 20 '15 at 23:16
• It's a cooking game, I get to the point where I go near to the stove, press space and it shows a debug message I made. Now I need to change the sprite to an animated stove with fire instead of the debug message and then reverse it by pressing space again. – d4ni3lb Jul 22 '15 at 1:42
• I would use the animator and change states to transition to different animations... Make your default animation contain one image (unlit stove) then when you press space bar, change state to transition to lit stove image sequence. This is basic stuff and not unique to you... Look at a basic animation tutorial on YouTube, there are plenty. – Savlon Jul 22 '15 at 6:57

You do not have to drag drop animation controller to your script instead you can add component to game object using inspector. Add an Animator component first.