官术网_书友最值得收藏!

Parent/Child relationship

Before we make our first prefab, a concept that is both useful and important is parentage. In our Hierarchy view, we can have GameObjects with other GameObjects attached to them in a Hierarchy. We call the primary objects as parents, and the secondary objects are called children. When these hierarchies exist, there are many benefits from an organizational standpoint as well as for practical application.

Where there is a series of objects connected together in such a manner, if something on the parent object is changed--such as being moved, rotated, or scaled--all the attached objects do the same in relation to the parent.

Parenting is something that also applies to prefabs. With that in mind, we will parent our objects in the scene together and make a prefab from them; let's perform the following steps:

  1. Take a look at our Hierarchy view; we should still have Platform, Hello, and World:
  1. Select Hello and drag it up onto Platform until you see a light blue oval over the destination. Then, release the mouse button:
  1. Now, do the same thing for the World object. After you are done, you should see this in your Hierarchy view; your Hello and World objects are now children of Platform:

If you click on the Play button now to test your app, even after parenting the Hello and World objects, they will fall onto the Platform.

Here's a quick test to see the effect on the children when we transform the parent. Let's look at the following steps:

  1. With Platform selected, move your mouse to the Transform component in the Inspector. Click in the Z-axis box. Change the number in the field to 4:
  1. Now, click on and drag the Z axis left and right to move the platform:

As you can see, the words follow along without any issue. If you were to do the same thing to the scale on the X axis, it would squeeze and expand.

主站蜘蛛池模板: 乌鲁木齐市| 宜兰市| 抚宁县| 张北县| 雅安市| 蓝山县| 泗阳县| 盐源县| 军事| 株洲市| 陵水| 义乌市| 固镇县| 伊春市| 荆门市| 临猗县| 闵行区| 德格县| 额敏县| 巴彦淖尔市| 东海县| 长宁县| 宿迁市| 五指山市| 邓州市| 兰西县| 独山县| 行唐县| 榕江县| 兴隆县| 枣庄市| 彝良县| 岐山县| 拉萨市| 南涧| 翼城县| 河西区| 靖宇县| 鞍山市| 石狮市| 临海市|