1、Start() 開始方法;
2、Update() 正常更新邏輯,每渲染一幀都會調用
3、FixedUpdate() 不受幀率的變化,固定的時間間隔被調用,怎么設置間隔?Edit->Project Setting->time下面的Fixed timestep
4、LateUpdate() 會在每一幀中被調用。在所有Update函數被調用之后才執行。有利於程序的有序執行。(例如:跟隨攝像機就應該在LateUpdate執行,因為它跟隨的對象也許需要在Update中執行
5、OnGUI() 游戲界面繪制、更新
6、OnCollisionEnter(Conllision other) 在剛體與剛體開始接觸時候調用此方法,(記住是剛體之間的碰撞)
7、OnCollisionStay(Conllision other) 在剛體與剛體碰撞的過程中,調用此方法 每幀都會調用此方法,知道碰撞結束;
8、OnCollisionExit( Conllision other) 在剛體與剛體停止接觸時,調用此方法
9、OnTriggerEnter(Collider other) 當Collider(碰撞體)進入trigger(觸發器)時調用,這個消息被發送到觸發器碰撞體和剛體(或者碰撞體假設沒有剛體)。注意如果碰撞體附加了一個剛體,也只發送觸發器事件
10、判斷兩個物體之間的距離 Vector3.Distance( position1,position2) <distance ;
position1 和position2是需要判斷的兩個物體transform的position,distance是距離。
11、讓一個物體朝向另一個物體
transform.LookAt(other.transform);
12、創建一個對象,並讓它有一個運動軌跡
- Transform shoot = (Transform)Instantiate(shotPrefab,firePoint.gameObject.transform.position,
- firePoint.gameObject.transform.rotation);
- shoot.rigidbody.velocity= transform.TransformDirection(Vector3.forward*100f);
firePoint 是一個Empty對象,它提供初始位置,shotPrefab是一個預制對象,shoot.rigidbody.velocity= transform.TransformDirection(Vector3.forward*100f);是讓這個物體向前運動
13、旋轉和移動
transform.Rotate(new Vector3(x,y,z)) ; transform.Translate(new Vector3(x,y,z));以某個軸為軸旋轉或者移動就修改某個坐標的值,
