这是摄像机跟随角色脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowTags : MonoBehaviour
{
//玩家
public Transform player;
//平滑值
public float smoothing=3;
//高度
public float y = 5;
//距离
public float z = -6;
// Start is called before the first frame update
void Start()
{
//获取玩家目标
player = GameObject.FindGameObjectWithTag("Player").transform;
}
//帧率固定的方法
private void FixedUpdate()
{
//移动跟随目标位置
Vector3 targetPos = player.position + new Vector3(0, y, z);
//平滑跟随
this.transform.position = Vector3.Lerp(transform.position, targetPos, smoothing * Time.deltaTime);
}
}