Enter and exit with animations

This is my enter and exit script what should i do to make my character play an animation clip while entering and exiting?
My enter button is ‘E’
How can i edit the script to play an animation?
How can i make my character open the car door and sit in it?


 var car : Transform;
 var player : Transform;
 var exitPoint : Transform;
 var doorTriggerLeft : Transform;
 var PlayerCamera : Camera;
 var CarCamera : Camera;
 var isPlayerVisible : boolean;
 
 
 function Update(){
     if (Input.GetButton("e")&& isPlayerVisible){
         // make player invisible and still standing
         player.gameObject.SetActiveRecursively(false);
         player.gameObject.active = false;
         // parent player to Exit Point
         player.parent = exitPoint.transform;
         player.transform.localPosition = Vector3(-1.5,0,0);
         // parent PlayerParent to car
         exitPoint.parent = car.transform;
         exitPoint.transform.localPosition = Vector3(-0.5,0,0);
         // Enable Car as controllabe object
         GameObject.Find("Car").GetComponent("CarController").enabled=true;
         GameObject.Find("Car").GetComponent("CarUserControl").enabled=true;
         PlayerCamera.enabled = false;
         CarCamera.enabled = true;
         }
         else
         {
     if (Input.GetKeyUp("f")){
         // make character visible again
         player.gameObject.SetActiveRecursively(true);
         player.gameObject.active = true;
         // unparent player from everything
         player.transform.parent = null;
         // parent Exit Point to door Trigger
         exitPoint.parent = doorTriggerLeft.transform;
         // disable car as controllable
         GameObject.Find("Car").GetComponent("CarController").enabled=false;
         GameObject.Find("Car").GetComponent("CarUserControl").enabled=false;
         PlayerCamera.enabled = true;
         CarCamera.enabled = false;
 
         }   
     }
 }
 
 function OnTriggerEnter(Player : Collider) {
     isPlayerVisible = true;
     }
 
 function OnTriggerExit(Player : Collider) {
     isPlayerVisible  = false;
     }

First you have to add an animator or animation component to the object what you want to animate(animator if its generic or humanoid animation the clip, animation if its a legacy clip, see all this on the clip rig avatar) when you aded the animator component then you have to assign it an avatar, use the one what comes with the clip, after this create an animator controller on the assets tab, after this you can open the animator window on window: animator.

After this you will see some states, create one with a name and assign it a clip.

After all this you can go to the script and use the next:

Animator anim;

void Awake () {
anim = GetComponentAnimator(); } //here use the <> simbols on the Animator word, i cant write here this…//

function OnTriggerEnter(Player : Collider) {
isPlayerVisible = true;
anim.Play(“nameofanimatorstateclip”);
}

function OnTriggerExit(Player : Collider) {
isPlayerVisible = false;
anim.Play(“nameofanimatorstatecliptwo”);
}

Too you can use a boolean with the animator for end the clip at the right moment and transition between the two clips perfectly on the frame what you want, but this is more difficult, for this you will have to see some tutorials, here you have some good : Controlling Animation - Unity Learn

My Player has an animator Controller called Animator 1

My animations are called Entering

Can you please edit these scripts?

using UnityEngine;

using System.Collections;



public class PlayAnimation : MonoBehaviour

{

    Animator anim;

    // Use this for initialization

    void Awake()

    {

       

    }



    private void NewMethod()

    {

        anim.GetComponent<Animator>();

    }



    // Update is called once per frame

    void Update()

    {

        if (Input.GetKeyDown(KeyCode.A))

            anim.Play("Entering");

    }

}

@juan_poder_azure