raycast gets wrong layer

I have a sea on layer (4:“Water”) and cube on “Ignore raycast” (cube’s layer is not important).
so I attach my script to the cube that trys raycast from cube’s position to Vector3.down*30.0f on layer (NameToLayer) “Water”. and it finds the cube !!!

can someone explain me how does it happened and how to fix this…

The RayCast expects a LayerMask (32 bit field), you’re passing a layer number (number from 0 to 31).

Use LayerMask.GetMask() instead of NameToLayer.

it worked! thank u very much.