Collision not working

Hello.
First the script:

void Atacar()
    {
        Debug.Log("Start");
        Collider2D[] circuloAtaque = Physics2D.OverlapCircleAll(ataquePos.position, rangoAtaque);
       
        if(EsFisico)
        {
            Debug.Log("One");
            circuloAtaque[0].GetComponent<ControladorEstadisticasJugador>().DañoFisico(dañoFisico);
        }

        if(EsMagico)
        {
            Debug.Log("Two");
            circuloAtaque[0].transform.GetComponent<ControladorEstadisticasJugador>().DañoMagico(dañoMagico);
        }
        Debug.Log("Finish");
    }

The problem is found after debug(“One”). Since the following line doesn’t execute, BUT it works, sometimes it doesn’t make the correct reference, but when the entity moves a little bit, it starts to work.
Also previously I had a for but it didn’t work in any way.
What will be the error?

To be more specific, the code works when it wants…

Shouldn’t you be checking the length of this array before just blindly dereferencing the first item based on unrelated booleans??

Also, what do you mean by this:

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

You may edit your post above.

I mean using a for?

No, by checking that it has at least one entry.

if (circuloAtaque.Length > 0)
{
  // now we know it has at least ONE entry, entry [0]
}

I’m saying if that array is returned with zero entries in it, line 9 and line 15 above will throw an index out of range error.

If you care about the other things it hits, then yes, a for() loop would be one way to consider them all.

What you suspected is correct, if there is an entity inside. But apparently, checking, 3 objects came out. So on console I saw that those 3 objects are: 2 by the player and 1 by the enemy (which is the one with the script). It still fails, but it is almost unnoticeable

Also add a CompareTag that makes things even easier