1.创建空object
2.将上面object放入canvas中
3.为之加入组件:UI->Scroll Rect
4.在这个object中加入2D的Panel
5.确定这个Panel大小
6.放入你的控件(按钮之类)
7.将这个panel拖入到object的Conent栏位中
试试吧...
参考文章:
Create A Level Select Scroll Menu - Unity 4.6
Need an inspiration to follow this post?
If you're inspired and want to learn, then, let's start the learning.
1. To begin, we need to create a Unity Project, if one is not existing already. Create a New Scene named Level Select.
2. Create a Canvas by navigating to Create->UI->Canvas in the Hierarchy.
3. Create an Empty GameObject and rename it as ScrollView. Make it the child object of the Canvas.
4. With the ScrollView selected in the Hierarchy, move to the Inspector panel and click on Add Component->UI->Scroll Rect to add a Scroll Rect script to the ScrollView object.
Once you do it, modify the configurations as in the image below.
- We have unchecked the Horizontal checkbox, as we do not want the horizontal movement.
- The Deceleration Rate is set to a very low value of 0.0001 for the rate at which the ScrollView decelerates. Lower the value, lesser the movement on release of the cursor / touch.
5. Add a Text component within the Canvas we created earlier and name it TextSelectlevel.
- Change the Text to be displayed in the Text (Script) as SELECT LEVEL.
- Check the Best Fit checkbox. Set the Min Size to 10 and Max Size to 50 (or any value you like, for that matter).
- Place the Text somewhere near the top to make it look like a Menu Heading. Position the four anchor points at the edges of the Text.
(Take a look at the image below)
6. Select the Rect Transform tool from the tools section and resize the ScrollView as in the GIF below
7. Right Click on the ScrollView in the Hierarchy and create a Panel. Resize the panel as shown in the gif below to add our Level buttons.
Note: In case you want the Scroll Rect to Resize dynamically, place the anchor point of it's to the corners as in the image below
8. Create a Button inside the Panel. Rename it as Level1 and set it's Text component to LEVEL 1.
Position it near the top end of the Panel. Resize it as per your needs and place the anchor points to it's edges to resize the button dynamically.
Check the Best Fit checkbox of the Text component to resize the Text.
9. Duplicate the Button by pressing ctrl+D while the Level1 button is selected. Rename and reposition the button according to your needs. Also, reposition the anchors of each button to their edges. The below image shows a sample arrangement of the buttons.
11. If the Select Level text is not center aligned, you can do so as in the image below