Raycasting with layermask trouble

I’m new to raycasting, so I borrowed this script then added the layerMask.

var Target : GameObject; 
var layerMask = 1 << 9;

function TargetMouseSelect() : GameObject {

var ray : Ray = camera.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;

	if(Physics.Raycast (ray, hit, Mathf.Infinity,layerMask)){
		if (hit.collider.gameObject){
			Target = hit.collider.gameObject;
		}
	}
}
//

function Update(){



	if(Input.GetMouseButtonDown(0)){
		TargetMouseSelect();
		if(Target!= null)GameObject.Find("Player").GetComponent(PlayerController).target = Target.transform;
	}

	
}

The problem is, I can only target objects obscured by the layerMask once, then it ceases to function. Can anyone figure this one out?

Also, if I invert the layerMask, the Target is automatically set to a layer 9 object, without me invoking the method.

Actually, I realized that the IgnoreRaycast layer solves this problem, but if someone could explain the use of custom layerMasks, it would be greatly appreciated for more general use.

It’s easier if you just use the LayerMask type.

var layerMask : LayerMask;

–Eric