How can I code an enemy attack? (Top Down Melee Attack)

So i already have code that makes it so when a player gets in range, the enemy aggros and moves towards the player, if the player touches the enemy they take damage, however I want to code it so that when a player enters another range that is closer, the enemy will swing at the player. I also want it so the enemy is locked in place when swinging and the swing has a cooldown. I also want to know how I can make it so when a player enters aggro range, the enemy will do the run animation, because as of now he just moves towards him while doing the idle animation. Im very new to both coding and unity and I don’t know how to do these things, this is my first time doing any sort of game development. I watched a simple tutorial and it only explained how to code the idle animation and the death animation. Any help is appreciated.

Hi, i recommend you to check out this tutorial

(It’s part 51 tho, so maybe u need to check out the other parts as well)