Hero attacking enemy in range

I’m trying to check if the enemy i selected with a mouse click is inside my hero range(for that, i made a sphere with a trigger).

My Script for select a target(its working)

void Targeting() {
        if (Input.GetMouseButtonDown(0)) { // when button clicked...
           RaycastHit hit; // cast a ray from mouse pointer:
           Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
           int mask = 1 << 9;
           // if enemy hit...
           if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask)) {
               if (hit.transform.tag == "Enemy") {
                   selectedTarget = hit.transform; // set the new one...
               }
           }
        }
     }

And now my code for adding all enemy inside the attack range, i use a sphere trigger for that.

void OnTriggerEnter(Collider col) {
        if (col.transform.tag == "Enemy") {
            gameObject.transform.parent.GetComponent<PlayerControl>().inimigosDentroDaRange.Add(col.gameObject);
        }
    }

    void OnTriggerExit(Collider col) {
        if (col.transform.tag == "Enemy") {
            gameObject.transform.parent.GetComponent<PlayerControl>().inimigosDentroDaRange.Remove(col.gameObject);
        }
    }

And its working, all enemys inside my attack range are in the list.

The Targeting function and the list are inside my PlayerControl script.

But how i can check if the selected enemy is in my list?

So you want to iterate through the List of your current enemies that are within your Attack range and check them against your Target.

So you need 2 things, you need a reference to your Selected Enemy and a List of all Enemies inside your Attack Range.

List<Enemy> enemiesWithinRange;  //  List<Enemy> of enemies within range.

Enemy currentSelectedEnemy;  //  Your currently selected enemy. Notice it needs to be the same type as that which your List<Enemy> above is.

//  Iterate through the list to find if your enemy is within range or not.
foreach(Enemy enemies in enemiesWithinRange)
{
  if(enemies == currentSelectedEnemy)
  {
    //  Yes your target enemy is within range :) Do something with it here.
  }
}

Does this answer your question?