using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//摄像机跟随主角
public class FollowPlayer : MonoBehaviour {
Transform m_player;//主角
Vector3 m_offset;//偏移量
float speed = 20;//跟随速度
private void Awake()
{
m_player = GameObject.FindWithTag(Tag.player).transform;
m_offset = transform.position - m_player.position;
}
private void Update()
{
//利用插值运算实现移动
//参数:1、摄像机当前的位置,2、主角移动后的位置+偏移量=摄像机应该在的位置,3、插值速度
transform.position = Vector3.Lerp(transform.position, m_offset + m_player.position, speed * Time.deltaTime);
}
}