Cant play animation in animator

i’m making a game in 2d and whenever i create an animation sprite, an animator controller is created automatically, i dont know why, i once tried it but i thought it wouldnt be necesary for animations i just want to make in 2d… so after trying many times to play an animation without the animator (because unity says i have to set the animation legacy, which i dont know where), i gave it a try to play animations in the animator… i searched through the script reference and wrote the code just like this:

#pragma strict

var velocity : float = 8;

function Update ()
{
    var movement = Input.GetAxis("Horizontal") * velocity;

    transform.Translate(Vector2.right * movement * Time.deltaTime);

    if(Input.anyKey)
        Animator.Play("move");
}

the error that unity says is : Assets/PlayerControl.js(12,26): BCE0020: An instance of type ‘UnityEngine.Animator’ is required to access non static member ‘Play’.

so i tried to do this:

function Start ()
{
    //var anim = GetComponent("Animator");
}

function Update ()
{
    var movement = Input.GetAxis("Horizontal") * velocity;

    transform.Translate(Vector2.right * movement * Time.deltaTime);

    if(Input.anyKey)
        anim.Play("move");
}

and another error occurs: Assets/PlayerControl.js(17,17): BCE0005: Unknown identifier: ‘anim’.

i just want to play one simple animation that will just change the sprites. i know how to play animations without the animator… so please tell me what to do with it… how to stop unity auto creating animator controller or set the animation legacy, or how to fix this problem with the animator script.

You do know what the // means don’t you? This is telling the compiler to ignore the line.

Try the following

var anim : Animator;

function Start ()
{
    anim = GetComponent("Animator");
}
 
function Update ()
{
    var movement = Input.GetAxis("Horizontal") * velocity;
    transform.Translate(Vector2.right * movement * Time.deltaTime);
    if(Input.anyKey)
        anim.Play("move");
}