카메라 이동 2D
[SerializeField] private Transform target; // 카메라가 쫓아다닐 대상 (플레이어)
[SerializeField] private float smoothTime = 0.3f; // 부드럽게 이동하는 시간
private Vector3 velocity = Vector3.zero; // 값의 변화량 (=현재 속도)
private void LateUpdate()
{
// 월드 좌표 = TransformPoint (로컬 좌표)
Vector3 targetPosition = target.TransformPoint(new Vector3(0, 0, -10f));
// 목표 위치까지 부드럽게 이동할 때 사용하는 메소드
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
}
카메라 이동 3D
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
[SerializeField] private GameObject _target;
[SerializeField] private Vector3 _offset;
void LateUpdate()
{
transform.position = _target.transform.position + _offset;
}
}
'유니티' 카테고리의 다른 글
캐릭터 이름 표시 (TextMeshPro) (0) | 2023.11.28 |
---|---|
마우스의 위치 (0) | 2023.11.28 |
타일맵 (1) | 2023.11.27 |
2D 이동 (position, velocity, Input System) (0) | 2023.11.27 |
월드 좌표와 로컬 좌표 (0) | 2023.11.27 |