Interactions with another character

Hi, i am new here and i need some help with the interactions of my character against the enemy.
How i can make the character play the animation of damage when the enemy makes a hit, and the enemy dies when it have a determined acount of hits?
and follow the character when its a certain distance?

This is (to me) a small degree of AI, however not too complicated.

Assuming you already have your 3 animations (attacking, getting hit, and running/chasing something), then the best way is to setup 2 scripts. One that is on the player which handles all the players “stats” such as health, speed, and so on… Then another on your enemy which handles the “AI” side of things - being able to attack, being able to chase after the player, stopping its pursuit if the player gets too far too fast from the enemy, and so on…

Place a Trigger collider on your enemy with a Rigidbody - make sure your player also has a rigidbody and some type of collider (doesnt have to be a trigger).

(all code here is C#, untested)

In your AI Script:

void OnTriggerEnter(Collider coll){
if(coll.gameObject.tag == "Player"){
coll.GetComponent<PlayerStats>().DoDamage(20);
//This ideally calls the public "DoDamage" function, passing the number of damge through to the player, who can then interpret that number, recieve damage and play an animation.
}
}

And in your PlayerStats script:

private health = 100; //global variable
private anim = gameObject.GetComponent<Animator>(); //get the animator on your player - so make sure it has one attached
    
    public DoDamage(int damageDone){
    if(damageDone > 0){
    health -= damageDone;
    anim.Play("attacked"); //play the animation on your player called "attacked".
    }
    if(health <= 0){
    anim.Play("dead"); //If the player has no more health to lose, play the animation called "dead" on your player
    }

This is a very basic solution, you can get far more in depth and specific with things, but in a general scope to get what you want to work, that is the idea. The same logic would be applid on your AI script for the player to do damage and “kill” the enemy.

With “following” your player, there are a few ways to do it. In my opinion the best way is to create another game object with a trigger collider, and attach it to your enemy, making that collider essentially the “range” you want the enemy to be able to detect the player in, but then youd have to create a third script - so to keep it simple, create a second trigger collider and make it much larger than your first one on your enemy.

In your AI Script:

void OnTriggerStay(Collider coll){
if(coll.gameObject.tag == "Player"){
Follow(coll.gameObject.transform, 30f);
}
}

void Follow(transform objectToFollow, float speed){
gameObject.transform.position = Vector3.MoveToward(gameObject.transform.position, objectToFollow.position,speed * Time.deltaTime);
//or you can move by velocity:
//gameObject.GetComponent<Rigidbody>().velocity += gameObject.transform.forward * speed * Time.deltaTime;
}

Which is a very very basic approach to this.