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));
        
    }
}

代码就这么多,感谢您的阅读!

posted @ 2019-05-16 09:55  剑起苍穹  阅读(3666)  评论(0编辑  收藏  举报
/*鼠标点击特效*/