unity攝像機的平滑過渡,平滑緩沖


用的是這個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));
        
    }
}

代碼就這么多,感謝您的閱讀!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM