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.


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.


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.


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


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)