Unity设置相机跟随物体


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

/*by Alexander*/


//相机跟随脚本
public class CameraTracker : MonoBehaviour
{
    public Transform playerTransform;//跟踪的对象
    private Vector3 offset;


    void Start()
    {
        //         当前位置              物体的位置
        offset = transform.position - playerTransform.position;//计算相对距离
    }

    void Update()
    {
        transform.position = playerTransform.position + offset; //保持相对距离
    }
}



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM