Having trouble with melee attack script

Here’s the aforementioned script:

    public float attackDuration = 0.3F;

    public bool attacking;

    [HideInInspector]


    void Start()
    {

    }

    void Update()
    {
        if (Input.GetButtonDown("Attack"))
        {
            attacking = true;
        }
        EnableDamage();
    }

    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.tag =="Enemy")
        {
            if (col.tag == "Enemy")
            {
                col.SendMessage("LevaDano", 1, SendMessageOptions.DontRequireReceiver);
            }
        }
    }

    void EnableDamage()
    {
        if (attacking == true) return;
        attacking = true;
        StartCoroutine("DisableDamage");
    }

    IEnumerator DisableDamage()
    {
        yield return new WaitForSeconds(attackDuration);
        attacking = false;
    }

The main problem is that i can’t get attacking back to false no matter what. How to proceed? Also, feel free to warn me about any other bugs.

You can’t get it back to false because you’re consistently setting it to true, and never back to false.

So, On your Update()

You have: If Attack, Set attacking to True.

You also have it running “EnableDamage” on every frame.

If Atacking is true you break out of it. Which, it will be always. DisableDamage will never trigger.

Try this:

void OnTriggerEnter2D(Collider2D col)
     {
         if (col.tag =="Enemy")
         {
             if (col.tag == "Enemy")
             {
                 col.SendMessage("LevaDano", 1, SendMessageOptions.DontRequireReceiver);
             }
         }
attacking = false; //Will ALWAYS set to false even if they dont hit their desired target.
     }