Unity用坐标来判断是否点击在UI上,并调用

        if (Input.GetMouseButtonDown(1))
        {
            //EventSystem.current就是场景中的EventSystem
            PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
            eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

            List results = new List();
            EventSystem.current.RaycastAll(eventDataCurrentPosition, results);

            if (results.Count > 0)
            {
                results[0].gameObject.GetComponent

你可能感兴趣的:(Unity)