本文讲解:在有的应用中会使检测某个物体,但这个物体(A物体)的前方还有一个物体(B物体)也就是说射线检测优先检测到B物体,以至于阻挡住我点击A物体或者出现两种点击结果这种情况的处理方法。
if (Input.GetMouseButtonDown(0))
{
Vector3 mouseposition = Input.mousePosition;
Ray ray = Camera.main.ScreenPointToRay(mouseposition);
RaycastHit hit;
int layerToInclude = LayerMask.NameToLayer("NeedClick");//需要检测的层
int layerMask = 1 << layerToInclude;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
{
}
}