【Unity3D Keynote】
1、场景文件扩展名为.unity。
2、up为Y正方向,down为Y负方向,right为X正方向,left为X负方向,forward为Z正方向,back为z负方向。基础物体本身坐标系。
3、在Scene工具条中可以设置Scene视图绘制模式:
4、给一个GameObject添加RigidBody,即可实现碰撞效果。
5、按以下代码添加GUI:
1 //模型移动速度 2 var TranslateSpeed = 20; 3 //模型旋转速度 4 var RotateSpeed = 1000; 5 //游戏绘制UI 6 function OnGUI() 7 { 8 //设置GUI背景颜色 9 GUI.backgroundColor = Color.red; 10 11 //按钮点击旋转、平移事件 12 if(GUI.Button(Rect(10,10,70,30), "向左旋转")){ 13 transform.Rotate(Vector3.up *Time.deltaTime * -RotateSpeed); 14 } 15 16 if(GUI.Button(Rect(90,10,70,30), "向前移动")){ 17 transform.Translate(Vector3.forward * Time.deltaTime *TranslateSpeed); 18 19 } 20 21 if(GUI.Button(Rect(170,10,70,30), "向右旋转")){ 22 transform.Rotate(Vector3.up *Time.deltaTime * RotateSpeed); 23 } 24 25 if(GUI.Button(Rect(90,50,70,30), "向后移动")){ 26 transform.Translate(Vector3.forward * Time.deltaTime * -TranslateSpeed); 27 } 28 29 if(GUI.Button(Rect(10,50,70,30), "向左移动")){ 30 transform.Translate(Vector3.right * Time.deltaTime *-TranslateSpeed); 31 } 32 33 if(GUI.Button(Rect(170,50,70,30), "向右移动")){ 34 transform.Translate(Vector3.right * Time.deltaTime * TranslateSpeed); 35 } 36 37 //将旋转平移的系数显示在屏幕中 38 GUI.Label(Rect(250, 10,200,30),"模型的位置" +transform.position); 39 40 GUI.Label(Rect(250, 50,200,30),"模型的旋转" +transform.rotation); 41 }
6、所有GameObject都可以添加GUI,均显示在屏幕上。不同GameObject添加的GUI如果位置重叠可能会相互覆盖。
7、Control appearances are dictated with GUIStyles. When you have a large number of different GUIStyles to work with, you can define them all within a single GUISkin. A GUISkin is no more than a collection of GUIStyles.
8、使用GUISkin
1 // JavaScript 2 var mySkin : GUISkin; 3 4 function OnGUI () { 5 // Assign the skin to be the one currently used. 6 GUI.skin = mySkin; 7 8 // Make a button. This will get the default "button" style from the skin assigned to mySkin. 9 GUI.Button (Rect (10,10,150,20), "Skinned Button"); 10 }
9、In Fixed Layout, you can put different Controls into Groups. In Automatic Layout, you can put different Controls into Areas, Horizontal Groups, and Vertical Groups。Notice that inside an Area, Controls with visible elements like Buttons and Boxes will stretch their width to the full length of the Area.
10、Unity 2.0 introduced UnityGUI, a GUI Scripting system. You may prefer creating user interface elements with UnityGUI instead of GUI Texts.
GUI Text是老技术,Unity官方建议优先使用UnityGUI。
11、A GUI Layer Component is attached to a Camera to enable rendering of 2D GUIs.
When a GUI Layer is attached to a Camera it will render all GUI Textures and GUI Texts in the scene. GUI Layers do not affect UnityGUI in any way.
GUI Layer跟GUI Textures, GUI Texts有关,跟UnityGUI的显示无关,是一项老技术,官方建议淘汰。
12、Text Meshes can be used for rendering road signs, graffiti etc. The Text Mesh places text in the 3D scene. To make generic 2D text for GUIs, use a GUI Textcomponent instead.
13、通过对象的 .renderer.material.mainTexture 可以修改GameObject的对象的贴图,以此可以实现动画。