Mobile Input and Vector2.Distance question

Ok so basically what I’m trying to do is get a tap on the enemy from the user and check if the distance between the enemy and player character is close enough to do damage to the enemy. The problem is that the Vector2.Distance shows no errors or anything but it wont work in game at all. It now won’t let me damage any enemies at all and I have MinDistance set to 0.5.
Any Suggestions guys?:

              int i = 0;
        while (i < Input.touchCount)
        {
            if (Input.GetTouch(i).phase == TouchPhase.Began)
            {
                RaycastHit2D hit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(i).position), -Vector2.up);
                 

                if (hit2D.collider != null)
                {
                    if (hit2D.collider.tag == "Enemy" && Vector2.Distance(transform.position,enemyM.transform.position) <= MinDistance)
                    {
                 
                        anim.Play(attackTrigger);
                        Debug.Log("Hit Enemy");
                        enemyM = hit2D.collider.GetComponent<EnemyManager>();
                        enemyM.TakeDamage(Str);
                       
                        
                      
                    }
                }

            }
            ++i;

In line 11 you calculate the distance between the current gameobjects’s position and the position of enemyM. In you code enemyM is not yet assigned any value. I guess you should add
enemyM = hit2D.collider.GetComponent();
before the if-statement