using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
/* 原理
1.相机跟主角有一定的距离
2.主角的位置减去相机的位置
3.让相机能够缓慢的跟随主角
*/
//主角
private GameObject player;
//方向向量
Vector3 offect;
//平滑速度
public float smoothSpeed;
void Start () {
//避免重复查找
if (player ==null)
{
//查找到主角
player = GameObject.Find("CartoonySoldier");
}
offect = player.transform.position - transform.position;
}
void Update () {
//Vector3.Lerp线性插值 无限的接近目标 永远不会到达目标
transform .position =Vector3.Lerp(transform.position, player.transform.position - offect, Time.deltaTime* smoothSpeed);
}
}