OverlapCircleAll does not collect other objects

I am trying to get all objects at a distance from the current object. the parameter is maxShootDistanceset to 3, and when the object, which is part of the layer ShootAt, approaches / in the circle, it is never matched, and my debugging outputs 0. Why doesn't he collect another object?

public class QuckShot : Gun {

    void Start () {
        StartCoroutine(shoot());
    }

    IEnumerator shoot(){
        while(true){
            Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, maxShootDistance, LayerMask.NameToLayer("ShootAt"));
            Debug.Log(hitColliders.Length); // This is always returning zero
            /*
             * Snipped other bits of code
             */
            yield return new WaitForSeconds(shootSpeed);
        }
    }
}

Here are the properties that are assigned to the object that should have been selected:

Female properties

Why is my code not capturing an object?

+4
source share
1 answer

This call:

LayerMask.NameToLayer("ShootAt")

NameToLayer returns the index of the layer (i.e.: 7), but OverlapCircleAll expects a bitwise layer mask (i.e.: 7th bit is turned on).

, . , .

:

1 << LayerMask.NameToLayer("ShootAt");

( .)

+3

All Articles