1. 程式人生 > >UGUI使用Scroll View,item有監聽會導致劃不動的問題

UGUI使用Scroll View,item有監聽會導致劃不動的問題

出現這個問題可以Button來註冊監聽

protected void RegisterButtonEvent(Button btn, UnityAction btnEvent)
    {
        if (null == btn) { return; }
        if (null == btnEvent) { return; }
        SetRaycastTarget(btn.GetComponent<Graphic>(), true);
        btn.onClick.AddListener(btnEvent);

    }

protected void SetRaycastTarget(Graphic image, bool enable)
    {
        if (null != image)
        {
            image.raycastTarget = enable;
        }

    }

這樣就可以按住按鈕的時候滑動了