유니티 최고/Unity
카메라 시점 조절하기
군포망나니
2022. 1. 22. 11:39
기본 idea : 오브젝트와 카메라 간의 거리 차이 계산하기
CameraMove 스크립트를 생성하고
카메라 이동에 관한건 LateUpdate() 에 코드를 넣는다 .
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMove : MonoBehaviour
{
Transform playerTransform;
Vector3 Offset;
void Awake()
{
playerTransform = GameObject.FindGameObjectWithTag("player").transform;
Offset = transform.position - playerTransform.position;
}
// Update is called once per frame
void LateUpdate()
{
transform.position = playerTransform.position + Offset ;
}
}