Raycast doesn't hit anything when given a mask

I need to detect enemies from player position. I’m casting a ray with this code:

Vector3 mousePosition = Input.mousePosition;
Vector3 vector3=Camera.main.WorldToScreenPoint(transform.position);
Vector3 mousePositionInWorld=mousePosition - vector3;
Vector3 rayDirection = mousePositionInWorld - transform.position;
ContactFilter2D contactFilter = new ContactFilter2D();
contactFilter.useTriggers = true;
RaycastHit2D[] hits = new RaycastHit2D[1];
Physics2D.Raycast(projectileExit.position, rayDirection,contactFilter, hits,10);

projectileExit is an object located where projectiles should come from. When I use the mask, hits[0] is null, even if I’m casting against layer where the player is. If I remove the mask, the cast works, so other parameters should be correct.

This is not a mask, this is a layer index.

Either expose a LayerMask to the inspector, use LayerMask.GetMask, or create a mask manually.

You can read this resource on bitmasks to understand the difference between a layer and a mask.