How to scroll to a specific element in ScrollRect with Unity UI?

后端 未结 10 2450
野的像风
野的像风 2021-02-12 04:03

I built a registration form for a mobile game using Unity 5.1. To do that, I use Unity UI components: ScrollRect + Autolayout (Vertical layout) + Text (labels)

10条回答
  •  我在风中等你
    2021-02-12 04:12

    width signifiy the width of childern in scroll rect (assuming that all childerns width is same), spacing signifies the space between childerns, index signifies the target element you want to reach

    public float getSpecificItem (float pWidth, float pSpacing,int pIndex) {
        return (pIndex * pWidth) - pWidth + ((pIndex - 1) * pSpacing);
    }
    

提交回复
热议问题