Ngui判断鼠标是否在UI界面上

此UI要加碰撞盒才能被支持


/// <summary>
    /// 鼠标是否在Ngui的UI界面上
    /// </summary>
    public static bool IsMouseOverUI
    {
        get
        {
            Vector3 mousePostion=Input.mousePosition;
            GameObject hoverobject = UICamera.Raycast(mousePostion, out UICamera.lastHit) ? UICamera.lastHit.collider.gameObject : null;
            if (hoverobject != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

通过UI相机射线检测碰撞UIt物体来实现判断

你可能感兴趣的:(Ngui判断鼠标是否在UI界面上)