Unity3D基础教程2-2:使用组件(Using Components)

2014-08-06 07:45:14|?次阅读|上传:huigezrx【已有?条评论】发表评论

关键词:Unity3D, 游戏, 虚拟现实|来源:唯设编程网

Unity Manual > User Guide > Building Scenes > Using Components

Unity 手册->用户指南->建立场景->使用组件

Components are the nuts & bolts of objects and behaviors in a game. They are the functional pieces of every GameObject. If you don't yet understand the relationship between Components and GameObjects, we recommend that you read the GameObjects page before going any further.

组件是对象的基本组成部分以及游戏里的行为。它们是每个GameObject(游戏物体)的功能件。如果你还没有理解组件与GameObject(游戏物体)之间的管理,我们建议你在这之前先阅读GameObjects页。

A GameObject is a container for many different Components. By default, all GameObjects automatically have a Transform Component. This is because the Transform dictates where the GameObject is located, and how it is rotated and scaled. Without a Transform Component, the GameObject wouldn't have a location in the world. Try creating an empty GameObject now as an example. Click the GameObject->Create Empty menu item. Select the new GameObject, and look at the Inspector.

一个GameObject(游戏物体)是许多不同组件的容器。默认情况下,所有的GameObject(游戏物体)自动拥有一个Transform(变换)组件。这是因为Transform(变换)决定了GameObject(游戏物体)被定位哪里,以及它是如何旋转和缩放。没有Transform的组件,GameObject(游戏物体)将没有一个位置(坐标),在世界里。现在尝试创建一个空的GameObject(游戏物体)作为例子。点击 GameObject->Create Empty 菜单项。选取新GameObject(游戏物体),并查看Inspector(检视器)。

Unity3D基础教程2-2:使用组件(Using Components)

Even empty GameObjects have a Transform Component 甚至空的GameObject(游戏物体)有一个Transform组件

Remember that you can always use the Inspector to see which Components are attached to the selected GameObject. As Components are added and removed, the Inspector will always show you which ones are currently attached. You will use the Inspector to change all the properties of any Component (including scripts)

记住,你总可以使用检视器图查看哪些组件连接到(附属于)选定的GameObject(游戏物体)。As Components are added and removed, the Inspector will always show you which ones are currently attached.作为组件被添加和删除,检视器会始终显示你哪些是目前连接。你You will use the Inspector to change all the properties of any Component (including scripts)你你将使用检视器去改变所有任何组件的属性(包括脚本)。

Adding Components 添加脚本

You can add Components to the selected GameObject through the Components menu. We'll try this now by adding a Rigidbody to the empty GameObject we just created. Select it and choose Component->Physics->Rigidbody from the menu. When you do, you will see the Rigidbody's properties appear in the Inspector. If you press Play while the empty GameObject is still selected, you might get a little surprise. Try it and notice how the Rigidbody has added functionality to the otherwise empty GameObject.

你可以添加组件到选定的GameObject(游戏物体),通过组件菜单。 现在,We'll try this now by adding a  we just created.我们将尝试这个,通过添加刚体到我们刚刚创建的空白GameObject(游戏物体)。选取它并从菜单那选择 Select it and choose Component->Physics->Rigidbody from the menu.。。。。。。

。 。When you do, you will see the Rigidbody's properties appear in the Inspector.当你这样做时,你将看到刚体的属性出现,在检视器里。 If you press  is still selected, you might get a little surprise.如果您按播放而空白的GameObject仍然处于选中状态,你可能会得到一些惊喜。尝试并注意刚体已经添加的功能如何对空白GameObject(游戏物体)其它方面。

Unity3D基础教程2-2:使用组件(Using Components)

An empty GameObject with a Rigidbody Component attached  一个空白的GameObject与一个刚体组件连接

You can attach any number or combination of Components to a single GameObject. Some Components work best in combination with others. For example, the Rigidbody works with any Collider. The Rigidbody controls the Transform through the Ageia PhysX physics engine, and the Collider allows the Rigidbody to collide and interact with other Colliders. A different example of Component combinations is a Particle System. They use a Particle Emitter, Particle Animator, and Particle Renderer to create a group of moving particles.

你可以连接任何数量或组件的集合到一个单一的GameObject。一些组件与其它组件结合在一起工作最好。例如,刚体与任意的碰撞器一起工作。刚体控制变换通过Ageia PhysX物理引擎,以及碰撞器运行刚体去碰撞和与其它碰撞器结合。一个组件集合的不同的例子是粒子系统。它们使用一个粒子发射器、粒子动画、以及粒子渲染去建立一个移动的粒子群。

If you want to know more about using a particular Component, you can read about any of them in the Component Reference. You can also access the reference page for a Component from Unity by clicking on the small ? on the Component's header in the Inspector.

如果你想去知道更多关于使用一个详细组件,你可以阅读关于它们在组件参考里。

<123>
发表评论0条 】
网友评论(共?条评论)..
Unity3D基础教程2-2:使用组件(Using Components)