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.