-
[Roll-a-Ball]CameraController 스크립트Unity(유니티) 2022. 4. 13. 13:17
offset : 동일 오브젝트 안에서 오브젝트 처음부터 주어진 요소나 지점까지의 변위차를 나타내는 정수형
시작 시 카메라와 플레이어의 위치 값을 뺀 후 offset에 저장하고 LateUpdate를 통해 이동 및 나머지 Update를 진행 후 함수를 실행하여 카메라의 위치 값을 player의 이동한 위치와 offset 값을 더해 player와 일정하게 거리를 위지하며 이동할 수 있도록 함
using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraController : MonoBehaviour { public GameObject player; private Vector3 offset; // Start is called before the first frame update void Start() { offset = transform.position - player.transform.position; } //다른 스크립트의 Update를 끝내고 LateUpdate를 실행 // Update is called once per frame void LateUpdate() { transform.position = player.transform.position + offset; } }
'Unity(유니티)' 카테고리의 다른 글
[2D,Bolt] 노드를 활용하기 위한 layout 셋팅 (0) 2022.04.15 [Roll-a-Ball] Rotator 큐브 회전 스크립트 (0) 2022.04.13 [Roll-a-Ball] PlayerController 스크립트 (0) 2022.04.13 [UIUXSamples(2)] Password InputField (0) 2022.04.12 [UIUXSamples(2)] UIManager 스크립트 (0) 2022.04.12