using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestCamera : MonoBehaviour {
public Vector3 offset = new Vector3(0, 5, -4);//玩家到相机的路径向量
Transform targetTran;
private Vector3 endPos;//插值运算中的终点坐标向量
public float followSpeed = 2;
// Use this for initialization
void Start()
{
targetTran = GameObject.FindGameObjectWithTag("Player").transform;
}
// Update is called once per frame
void Update()
{
endPos = targetTran.position + offset;//每帧更新相机终点坐标
transform.position = Vector3.Lerp(transform.position, endPos, followSpeed * Time.deltaTime);//相机的路径插值
Quaternion endQua = Quaternion.LookRotation(targetTran.position - transform.position);//每帧更新相机的终点旋转四元数
transform.rotation = Quaternion.Slerp(transform.rotation, endQua, followSpeed * Time.deltaTime);//相机的旋转插值
}
}