用的是這個smoothdamp 代碼很簡單,下面我們來看看代碼
using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> /// 相機從一個點到另一個點的平滑過渡,平滑緩沖 /// </summary> public class LiaGeQiu : MonoBehaviour { public GameObject cameraon;//初始攝像機的位置 public GameObject camerto;//另一個點的位置 private float speed = 1f;//緩沖的時間 時間越大緩沖速度越慢 private Vector3 velocity;//如果是3D場景就用Vector3,2D用Vector2 // Use this for initialization void Start () { } // Update is called once per frame void Update () { cameraon.transform.position = new Vector3(Mathf.SmoothDamp(cameraon.transform.position.x, camerto.transform.position.x, ref velocity.x, speed), Mathf.SmoothDamp(cameraon.transform.position.y, camerto.transform.position.y, ref velocity.y, speed),Mathf.SmoothDamp (cameraon.transform.position.z,camerto.transform.position.z ,ref velocity.z , speed)); } }
代碼就這么多,感謝您的閱讀!
