trying to play animation with C#

hi. im trying to animate an object (axe) to chop a tree. I dont know the code and I cant find tutorials to help.
Im telling it to run from a different piece of code.

Ive tried this code:

public Animation anim;

public void Swing()
{
    anim.Play();
}

also does anyone know what to drag into the box in the editor for the anim?

You Should use the Animator instead. That makes it much easier if you want to have more than just the Chopping animation.

the code should look somewhat like this.

public Animator animator;

void Swing(){
animator.SetTrigger("Chop");
}

Drag and drop the GameObject with the Animation component attached to it.
The Play method need the name of the animation you want to play.

anim.Play("myAnim");

yeah it wont let me drag the axe gameobject onto the script

You need to drag the AnimationClip into the Animation Component. Not the GameObject.

do i have to create an empty game object for it to go on first coz it wont let me just drag the .anim file?

No you should be able to drag it in just like that.
Can you make a screenshot of your inspector?

If there is a Animation component on the GameObject, you can drop it.

its even displaying when i press to search but just wont insert