Unity3D实现摄像头跟随目标

1. 创建一个目标(以圆球为例),再创建一个摄像头放在该目标的上方

2.创建一个脚本,脚本代码如下:

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

public class CamMove : MonoBehaviour
{
    public GameObject Player;
    public Vector3 offset;
    // Start is called before the first frame update
    void Start()
    {
        offset = transform.position - Player.transform.position;
    }

    // Update is called once per frame
    void Update()
    {
        transform.position = Player.transform.position + offset;
    }
}

3.再把该脚本添加到摄像机上

猜你喜欢

转载自blog.csdn.net/zldhxx/article/details/134909050
今日推荐