首页 > 代码库 > Unity3D Physics Keynote

Unity3D Physics Keynote

Unity3D Physics Keynote

1、在哪设置Layer Collision Matrix?

  "Edit"->"Project Settings"->"Physics"。

  

2、“Import Package”->"Physic Meterial",是Unity自带的物理材质包。

3、"Import Package"->"Character Controller",是Unity自带的视角控制器。

4、生成从摄像机到点的Ray,并判断与Ray相交的点。

  

5、关了断裂。

  

6、joint通过connectedBody进行与其它对象的连接。

  

7、布料,Interactive Cloth、Cloth Render两个组件共同组成了布料。通过以下代码可以操作布料:

 1 using UnityEngine; 2 using System.Collections; 3  4 public class Script_06_12 : MonoBehaviour  5 { 6  7     //布料对象 8     Cloth cloth = null; 9     10     void Start()11     {12         //获取布料对象13         cloth = (Cloth)GetComponent<InteractiveCloth>();14     }15     16     void OnGUI()17     {18         //移动布料19         if(GUILayout.RepeatButton("向上"))20         {21             cloth.externalAcceleration =  new Vector3(0,1,0);22         }23         if(GUILayout.RepeatButton("向下"))24         {25             cloth.externalAcceleration =  new Vector3(0,-1,0);26     27         }28         if(GUILayout.RepeatButton("向左"))29         {30             cloth.externalAcceleration =  new Vector3(1,0,0);31         }32         if(GUILayout.RepeatButton("向右"))33         {34             cloth.externalAcceleration =  new Vector3(-1,0,0);35     36         }37     }38 39 }
View Code

8、通过TrailRender组件可以渲染走过的路径。通过以下代码可以操作此组件:

 1 public class Script_06_13 : MonoBehaviour  2 { 3     //路径渲染对象 4     private TrailRenderer trialRender; 5      6     void Start ()  7     { 8         //获取路径渲染对象 9         trialRender = gameObject.GetComponent<TrailRenderer>();10     }11 12     void OnGUI()13     {14         15         if(GUILayout.Button("增加宽度",GUILayout.Height(50)))16         {17             trialRender.startWidth +=1;18             trialRender.endWidth   +=1;19         }20         21         if(GUILayout.Button("显示路径",GUILayout.Height(50)))22         {23             trialRender.enabled = true;24         }25         26         if(GUILayout.Button("隐藏路径",GUILayout.Height(50)))27         {28             trialRender.enabled = false;29         }30     }31 }
View Code