error : Unknown identifier: 'animator'.

i get the error: “Unknown identifier: ‘animator’.”

this is my script

#pragma strict

var X : float;

function Start () {
    //gathering normal object scale x
    X = transform.localScale.x;
    var animator = GetComponent("Animator");
}

function Update () {
    if (Input.GetKey("a")) { //Gamer pushes the "a" key 
      //set texture to normal position
      transform.localScale.x = -X;
      animator.Play("Run");
     }else if(Input.GetKey("d")){ //push d 
         //flip the texture
         transform.localScale.x = X;
         animator.Play("Run");
   } else {
        animator.Play("idle");
      
      }
}         

plz help

It is a scoping problem. You are declaring ‘animator’ inside Start() so its scope and lifespan is within the Start() function. Change the top part of your script as follows:

#pragma strict

var X : float;
private var animator : Animator;

function Start () {
    //gathering normal object scale x
    X = transform.localScale.x;
    animator = GetComponent(Animator);
}

Also avoid using the string version of GetComponent().