NGUI Camera's raycast hit through the UI Layer issue

Raycast into GUI?
http://forum.unity3d.com/threads/raycast-into-gui.263397/

int layer = 1 << 15;
Ray myray = UICamera.currentCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit[] hits = Physics.RaycastAll(myray, 1000.0f, layer);
int layer = 1 << 15;//NGUI layer, TODO modify with your own
void Update()
{
    if (Input.GetMouseButtonUp(0))
    {
        //UICamera
        if (UICamera.currentCamera != null)
        {
            Ray myray = UICamera.currentCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit[] hits = Physics.RaycastAll(myray, 1000.0f, layer);
            if(hits != null && hits.Length > 0){//hit the NGUI layer
                return;
            }
        }
    
} }

 

posted @ 2016-04-07 14:51  elfnaga  阅读(446)  评论(0编辑  收藏  举报