摄像机跟随脚本
摄像机始终与玩家Player保持固定距离
// An highlighted blockusing
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
private Transform target;//定义目标的transform组件
private Vector offset;//相机跟目标的距离
void Start()
{
target = GameObject.Find("Player").transform;
//获取脚本激活时摄像机与Player的位置向量
offset = gameObject.transform.position - target.position;
}
void Update()
{
transform.position = offset + target.position;
//以Player为起点,加上offset即为相机的位置
}