유니티
카메라(시점) 따라가기
Nhahan
2022. 6. 8. 23:14
캐릭터만 움직이고 카메라가 따라가지 않는다면 결국 조종하는 캐릭터가 화면 밖으로 나가 보이지 않게 될 것이다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowCamera : MonoBehaviour
{
[SerializeField] GameObject thingToFollow;
// this camera should be the same as the car's position
void LateUpdate()
{
transform.position = thingToFollow.transform.position + new Vector3(0, 0, -10);
}
}
위와 같은 스크립트를 만든다.
따라갈 오브젝트인 thingToFollow의 포지션과 카메라의 포지션을 맞추고, 같은 2차원 면에 놓여 아무것도 보이지 않을테니 Z축을 조절해준다. (new Vector3 부분)
그리고 ThingToFollow에 따라갈 오브젝트를 넣어준다.
이 경우에는 Car를 따라가게 되어있음을 알 수 있다.
728x90