ITween真的非常牛逼的東西,對於現在手頭的程序里的一般機器的運動還有一些物體的有規律移動,包括第一人稱視角的已知路線的自主漫游都可以用ITween來實現,既簡單又實用。
1,創建一個空對象,掛上ITween Path,根據需要設置Node Count的個數,然后再設置node內所有節點的位置
2,比如我要做這個攝像機沿着這個路徑進行漫游,那選中這個攝像機掛上PathAnimation.cs(不過這個是自已寫的類)
然后將PathAnimation的公共變量iTweenPath賦值
3,這樣的話我們就開始漫游了
1 using UnityEngine; 2 using System.Collections; 3 using System.Collections.Generic; 4 5 public class CarRunning_JX : MonoBehaviour 6 { 7 public List<PathAnimation> tiles = new List<PathAnimation>(); 8 public List<Transform> postions = new List<Transform>(); 9 public iTweenPath path_tuoChe; 10 public iTweenPath path_tile; 11 public PathAnimation tuoChe; 12 // Use this for initialization 13 void Start() 14 { 15 StartCoroutine(Running()); 16 } 17 18 // Update is called once per frame 19 void Update() 20 { 21 22 } 23 24 IEnumerator Running() 25 { 26 tuoChe.path = path_tuoChe; 27 tuoChe.Position = 0; 28 yield return StartCoroutine(tuoChe.RotateTo(10, 0.424f, Quaternion.Euler(270f, 90f, 0))); 29 yield return StartCoroutine(tuoChe.RotateTo(5, 0.5f, Quaternion.Euler(270f, 0f, 0))); 30 yield return StartCoroutine(tuoChe.RotateTo(5, 1, Quaternion.Euler(270f, 0, 0))); 31 for (int i = tiles.Count - 1; i >= 0; i--) 32 { 33 tiles[i].path = path_tile; 34 tiles[i].Position = 0; 35 tiles[i].path.nodes[0] = tiles[i].transform.position; 36 tiles[i].path.nodes[tiles[i].path.nodes.Count - 1] = postions[tiles.Count - i - 1].transform.position; 37 yield return StartCoroutine(tiles[i].RotateTo(3, 1, Quaternion.Euler(0, 180f, 270f))); 38 yield return new WaitForSeconds(1); 39 } 40 yield return null; 41 } 42 }
代碼是隨便挑了一節貼上的,大致的用法,很明了很簡單。
注:不過想在ITween Path上使物體勻速運動的話,一定要將路徑的每一個節點之間的距離必須一致。