Unity 카메라는 원활하게 작동합니다(실수를 수정해 주세요).

  • 스크립트를 카메라에 연결할 수 있습니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    
    
    public Transform player; // 跟随的游戏对象
    private Vector3 cameraOffset; // 相机的偏移

    [Range(0.01f,1.0f)] // 相机平滑度范围
    public float smoothness = 0.5f; // 初始平滑度为0.5;
    
    void Start()
    {
    
    
        cameraOffset = transform.position - player.transform.position;
        // 相机偏移位置等于相机位置减去玩家位置。
    }

    
    void Update()
    {
    
    
        Vector3 newPos = player.position + cameraOffset; // 新的位置等于玩家位置加上相机位置
        transform.position = Vector3.Slerp(transform.position, newPos, smoothness);
        // 相机的位置更新相机在a点上随着玩家b点的移动和玩家保持一样的距离设定相机偏移时的速度。
    }
}

Supongo que te gusta

Origin blog.csdn.net/qq_60839745/article/details/128725269
Recomendado
Clasificación