Enemy Attack Coroutine help

I have my Enemy.cs script where the Enemy must be in range in order to attack the Player. Once the Enemy is in range, I start the Attacking() Coroutine. The Player is also using a Coroutine for attacking, it works fine not sure if that is affecting this script.

Transform target; //The Player's transform

bool m_Attack, m_Attacking;

void Update()
{
        if (Vector3.Distance(transform.position, target.position) <= 1)
            m_Attack = true;
        else 
            m_Attack = false;

        if (m_Attack)
            StartCoroutine(Attacking());
}

IEnumerator Attacking()
{
     if (!m_Attacking)
     {
           m_Attacking = true;
           target.GetComponent<Health>().DealDamage(10f);
     }
        
      yield return new WaitForSeconds(1f);
      m_Attacking = false;
}

You cast the coroutine every frame, which in theory is why you have the bool check inside of your coroutine I assume, but you set m_Attacking to false even when the condition isn’t met, so every frame.

    IEnumerator Attacking () {
        if (!m_Attacking) {
            m_Attacking = true;
            target.GetComponent<Health>().DealDamage(10f);
            yield return new WaitForSeconds(1f);
            m_Attacking = false;
        }
    }

Oh thanks so much, now I see why my code didn’t work.