using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class CameraManager : MonoBehaviour
{/// <summary>/// 跟随的物体/// </summary>public GameObject _target;/// <summary>/// 跟随保持的高度/// </summary>public float _height;/// <summary>/// 跟随保持的距离/// </summary>public float _distance;Vector3 _pos;// Use this for initializationvoid Start(){_pos = transform.position;}// Update is called once per framevoid Update(){}void LateUpdate(){//去差值平滑相机跟随_pos.x = Mathf.Lerp(_pos.x, _target.transform.position.x, Time.deltaTime);_pos.y = Mathf.Lerp(_pos.y, _target.transform.position.y + _height, Time.deltaTime);_pos.z = Mathf.Lerp(_pos.z, _target.transform.position.z + _distance, Time.deltaTime);transform.position = _pos;}
}
直接上脚本,注释也很清楚了,