'LayerMask.NameToLayer not returning the expected value

I have the below code:

LayerMask targetLayer;
targetLayer = LayerMask.NameToLayer("TeamB");

However, instead of selecting my named layer, it selects 3 random ones (seemingly)? Default, TransparentFX and Ignore Raycast.

I also tried:

targetLayer = 7;

As I know that is the index of the layer, but it still doesn't work. What am I doing wrong? How do I programatically set my named layer?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source