Basic sword swing combat

Hello all, I am working on my first c#/unity project and am trying to implement combat into my game. The game is a side scrolling combat game. I currently have monsters which will attack the player causing him to lose health and be knocked back but now I am trying to implement the same for the monsters.

The player will be attacked in a crescent shape. I am not sure how to script this. I currently wrote a little pseudo code for what I think must happen.

Creates the trigger

Check to see if something is inside the trigger with the tag Enemy

If there is, sets a bool on the enemy to be attackable

If the Enemy leaves the trigger zone, the bool must be set to false.

If play attacks, all enemies with the inrange bool will be damaged

The monsters that are placed into the level using a spawner script which then names each monster Slime 1, Slime 2, etc.

The current knock back and damage I am using on the play is


void OnCollisionStay2D(Collision2D coll) {
if (coll.gameObject.tag == "Enemy")
ReceiveDamage (coll.gameObject.GetComponent<Enemy>().Damage);
}

void OnCollisionStay2D(Collision2D coll) {
	if (coll.gameObject.tag == "Enemy") {
		rigidbody2D.velocity = (knockForce * (transform.position - coll.gameObject.transform.position));
		StartCoroutine (knockBack (travelTime));
		movement = false;
		dash_rdy = false;

	}

}

This would be changed to reflect accordingly (ie, pull attack power from the character script)

How would be the best way to make this happen? I was making a collider trigger that would let me know if the mob was in range and then a swing would hit everything in range but that seems like a terribly efficient way to do things.

The combat style is similar to the game Terraria for those who require any example.

Any help would be much appreciated

I would create a parent script and handle the combat for the player and for the enemy the same way. This way you’d only have to script it once and then you can attach it to as many characters as you need.

In the specific classes you could change the variables for stuff as range, damage, how much force the knock back has, etc.