Unity通过射线识别UI层
    public GraphicRaycaster raycaster;
    public EventSystem eventSystem;

    private void Update()
    {


        PointerEventData pointerEventData = new PointerEventData(eventSystem);
        pointerEventData.position = Input.mousePosition;
        
        
        raycaster.Raycast(pointerEventData, results);
        foreach (RaycastResult result in results)
        {
            if (result.gameObject.tag.Equals("button") || result.gameObject.name.Contains("布线"))
            {
                Cursor.SetCursor(selectMouse, Vector2.zero, CursorMode.Auto);
            }
            else
            {
                Cursor.SetCursor(defaultMouse, Vector2.zero, CursorMode.Auto);
            }
            break;
        }
        
        results.Clear();
    }
上一篇