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;
}