01、控制相机跟随玩家

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowPlayer : MonoBehaviour
{

    public Transform Player;

    private float smoothing = 3.0f;
    private Vector3 offset;                 //偏移量

    void Start()
    {
        offset = this.transform.position - Player.position;         //一开始就获得初始的偏移量
    }

    // Update is called once per frame
    private void LateUpdate()
    {
        Vector3 targetPosition = Player.position + Player.TransformDirection(offset);       //加上在Player上的局部坐标偏移量
        this.transform.position = Vector3.Lerp(this.transform.position, targetPosition, Time.deltaTime * smoothing);
        this.transform.LookAt(Player);          //让摄像机始终望向玩家,同时保证玩家在摄像机的中心点
    }
}
原文地址:https://www.cnblogs.com/zhh19981104/p/8732494.html