Raycast and RaycastHit failure

I have a raycast which is meant to check that an object with the tag “Snake” is under the cursor. I’ve been trying to do some research on this problem, but none of it is making sense or it doesn’t solve the problem. Here’s the code:

if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),hit,Mathf.Infinity,LayerMask.NameToLayer("Default"))){
	Debug.Log("Raycast works");
	if(hit.transform.gameObject.CompareTag("Snake")){
		Debug.Log("RaycastHit comparison works");
}
}

Neither debug log displays, the objects with the tag have rigidbodies, and I am using #pragma strict. What could be the problem?

Have you tried it without the layer mask to see if that works?

You need to use 1<<LayerMask.NameToLayer("Default") instead. I think LayerMask.NameToLayer("Default").value will do, too.

EDIT: Nope, the .value version works only on LayerMasks, but LayerMask.NameToLayer returns an int, not a LayerMask. Whoever wrote that API wanted to do something evil.