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

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.

主站蜘蛛池模板: 博湖县| 嘉定区| 祁连县| 嘉黎县| 天祝| 特克斯县| 邵武市| 北宁市| 南部县| 永顺县| 大厂| 无棣县| 通城县| 永嘉县| 银川市| 姜堰市| 汾阳市| 安顺市| 拜泉县| 华宁县| 沛县| 乐山市| 古丈县| 大邑县| 台山市| 苍梧县| 大新县| 迁西县| 荆州市| 腾冲县| 庆城县| 鄂尔多斯市| 西林县| 罗田县| 淮滨县| 聂拉木县| 平谷区| 江源县| 双辽市| 皮山县| 太湖县|