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

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

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

Editing Components 编辑组件

One of the great aspects of Components is flexibility. When you attach a Component to a GameObject, there are different values or Properties in the Component that can be adjusted in the editor while building a game, or by scripts when running the game. There are two main types of Properties: Values and References.

组件主要的特性之一是灵活性。当你连接一个组件到一个GameObject(游戏物体),有不同的值或属性在组件里,在建造一个游戏的过程中可以在编辑器里调整,或在游戏运行时通过脚本进行处理。有两种主要的属性类型:值和引用。

Look at the image below. It is an empty GameObject with an Audio Source Component. All the values of the Audio Source in the Inspector are the default values.

查看下面的图片,这个一个空白的GameObject带有一个音频源组件。在检视器里的音频源组件的所有值是默认值。

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

This Component contains a single Reference property, and seven Value properties. Audio Clip is the Reference property. When this Audio Source begins playing, it will attempt to play the audio file that is referenced in the Audio Clip property. If no reference is made, an error will occur because there is no audio to be played. You must reference the file within the Inspector. This is as easy as dragging an audio file from the Project View onto the Reference Property.

这个组件含有一个简单引用属性,已经七个值属性。音频剪辑是引用属性。当这个音频源开始播放时,它将连接到播放音频文件,它是在音频剪辑属性里被引用。如果没有引用被设置,一个错误将出现因为没有音频去播放。你必须在检视器里引用一个文件。这非常简单,从项目视图(面板)里拖动一个音频文件到引用属性上即可。

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

Now a sound effect file is referenced in the Audio Clip property 现在一个声音效果文件被引用在音频剪辑属性里。

Components can include references to any other type of Component, file, or GameObject. For any of these, you just need to drag & drop the appropriate reference to the property. This type of referencing is very quick and powerful, especially when using scripting. To learn more about using scripts and properties, please view the Scripting Tutorial on the Tutorials page.

组件可以包括引用任何其它类型的组件、文件、或GameObject。对于这些,你仅需要拖放合适的引用到这个属性。引用类型是非常块和强大的,特别在使用脚本时。学习更多关于使用脚本和属性,请查看脚本教程在教程页。

The seven remaining properties on the Audio Clip are all Value properties. These can all be adjusted simply by clicking on them and pressing the Enter key. You can then enter any value you like using the keyboard, and press Enter to save the value.

在音频剪辑上剩余的七个属性被称为值属性。这些可以被调整仅仅通过在它们上面点击或按回车键。你可以输入任何你希望的值使用键盘,然后按回车键保存值。

You can also option- or right-click and drag on numeric properties to scroll values quickly

你也可以选择,或右键单击并在数值属性上面拖动去快速滚动值。(注意:在windows上左键单击)

The Value properties on the Audio Clip are all numeric, but some properties can be strings as well. For example, the Text Mesh Component contains a Text property, which accepts alphanumeric characters.

在音频剪辑上的值属性是数字,但一些属性可以也可是字符串。例如,文字网格组件包含一个文字属性,它接受字母数字字符。

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

Some values can contain text, like the Text property in the Text Mesh Component某些值可以包含文字,如在文本的Text属性网格组件

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