How do I use animations in 5.6.1,I'm doing a click to move Diablo style game, I've just started now I don't know how to use animations.

Hey, I’m doing a click to move game and I’ve downloaded a skeleton pack just to test and now I don’t know how to make the skeleton do the run animation when I click and when It reaches the location I clicked I want it to start the animation IDLE.
The Whole Code I’ve Write

public class ClickToMove : MonoBehaviour {
private Vector3 position;
public float speed;
public CharacterController controller;
public Animation run;
public Animation idle;
// Use this for initialization
void Start () {
position = transform.position;
}

// Update is called once per frame
void Update () {
	if(Input.GetMouseButton(0))
     {
        //Localizar donde ha clicado el jugador 
        locatePosition();
    }
    //Mover al Jugador donde ha clicado
    moveToPosition();
}
void locatePosition()
{
    RaycastHit hit;
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    if (Physics.Raycast(ray, out hit, 1000)){
        position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
    }
}
void moveToPosition()
{
    //Se mueve
    if (Vector3.Distance(transform.position, position)>1) { 
    Quaternion newRotation = Quaternion.LookRotation(position-transform.position);
    newRotation.x = 0f;
    newRotation.z = 0f;
    transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 10);
    controller.SimpleMove(transform.forward * speed);

        GetComponent<Animation>().Play(run.name);
    }
    
    //No se mueve
    else
    {
        GetComponent<Animation>().Play(idle.name);
    }
}

}

Thanks for your help, and sorry for my bad english.

Your best option should be to use a NavMeshAgent together with an animator blendtree.

There is a good section about this in the Unity Manual:

I will give a quick example how it is setup, its not perfect but it should get you started.

First you would need to setup your blendtree with Forward/Backward/Left/Right animations. If you want to keep it simple you could probably be ok with just the forward animation. You would also need to put in a Idle animation in the blendtree. Here is a picture of how it should look.

(You could expand the blend tree to make it look better, especially turning and stoppning.)

After you have setup the blend tree you can control the blend tree from the script.

Here is a modified version of your script that is using a NavMeshAgent to move the character around and then setting the Blendtree values correctly:

using UnityEngine;
using UnityEngine.AI;

[RequireComponent(typeof(NavMeshAgent))]
[RequireComponent(typeof(Animator))]
public class MoveCharacter : MonoBehaviour
{
    private NavMeshAgent _agent;
    private int _horizontalMoveHash;
    private int _verticalMoveHash;
    private Animator _animator;

    private void Start()
    {
        _agent = GetComponent<NavMeshAgent>();
        _animator = GetComponent<Animator>();
    }

    private void Update()
    {
        if (Input.GetMouseButton(0))
        {
            MoveToPosition(LocatePosition());
        }

        UpdateAnimations();
    }

    private void UpdateAnimations()
    {
        _animator.SetFloat("Vertical", Vector3.Dot(transform.forward, _agent.desiredVelocity), 0.1f, Time.deltaTime);
        _animator.SetFloat("Horizontal", Vector3.Dot(transform.right, _agent.desiredVelocity), 0.1f, Time.deltaTime);
    }


    private Vector3 LocatePosition()
    {
        RaycastHit hit;
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out hit, 1000))
        {
            return hit.point;
        }

        return Vector3.zero;
    }

    private void MoveToPosition(Vector3 target)
    {
        if (target == Vector3.zero) return;
        _agent.SetDestination(target);
    }
}

And here is how it look in the end:

96409-guide.gif