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