摄像机与主角位置保持不变

摄像机跟随脚本

  摄像机始终与玩家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即为相机的位置
}

猜你喜欢

转载自blog.csdn.net/weixin_44870508/article/details/102805982