2D mobile game attack button not working

I am trying to get a empty game Object with a collider that isn’t enabled and a script that stated when something enters the collider it damages it by the sword damage, it is only supposed to go every few milliseconds but it is flashing on and of every few frames and not waiting the proper amount of time.

Script :

using UnityEngine;
using System.Collections;

public class MeleeTrigger : MonoBehaviour {
public int swordDamage = 20;
private int swordDamageOld = 20;
private float dmgTimer = .3f;
private float dmgCoolDown = .3f;
public bool isAttack = false;
EnemyHealth enemyHealth;
Button button;

void Start()
{
button = GameObject.FindGameObjectWithTag(“MainCamera”).GetComponentInChildren();
}

void Update()
{
if (isAttack == true)
{
StartCoroutine(MeleeHoldDamage());
}
}

void OnTriggerEnter2D(Collider2D col)
{
if (col.isTrigger != true && col.CompareTag(“Enemy”))
{
col.SendMessageUpwards(“DamageEnemy”, swordDamage);
}
}

IEnumerator MeleeHoldDamage()
{
while (isAttack == true) {
button.meleeTrigger.enabled = true;
yield return new WaitForSeconds(0.5f);
button.meleeTrigger.enabled = false;
yield return new WaitForSeconds(0.5f);
button.meleeTrigger.enabled = true;
yield return new WaitForSeconds(0.5f);
button.meleeTrigger.enabled = false;
}
}
}

is Attack is set to true when the attack button is held down (handled by another script)
Thank you very much.

don’t start a coroutine in the Update

i.e. you are starting a new coroutine every frame for as long as isAttack is true.

also, please use [code ][/code ] tags when pasting code into the forums, really helps with readability, there is a sticky on them at the top of the scripting forum

I’m sorry but I am very new to this, were would I call it then?

I have it working thanks a lot you guys!