LayerMask mask = 1 << LayerMask.NameToLayer("UI"); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, 100000.0f, mask.value)) { ... }
原文:http://www.cnblogs.com/guxin/p/unity-mouse-raycast-to-specified-layer.html