단순 카메라 팔로우

2023. 1. 23. 23:41개인적인 공부/Unity

create FollwCamera C# script

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowCamera : MonoBehaviour
{

    // this things position (camera) should be the same as car's position

    // Update is called once per frame
    void Update()
    {
        transform.position = 
    }
}

 

Also Create Reference

 

if we want to access / change/ call anything other than this game object's transform, we need to create reference.

 

메인카메라가 게임 오브젝트

 

참조 하려고 할때 레퍼런스가 필요하다.

 

public class FollowCamera : MonoBehaviour
{

    [SerializeField] GameObject thingToFollow;

    // this things position (camera) should be the same as car's position

    
    void Update()
    {
        // transform.position = 
    }
}

새 스크립트 항목이 생겼다.
자동차를 선택한다.

레퍼런스를 플레이어 캐릭터에 적용하였다.

 void Update()
    {
        transform.position = thingToFollow.transform.position;
    }

 

하지만 보이지 않는다.

카메라가 x, y, z 축중에 z 축으로 보기 때문에 world와 카메라가 붙어 있기 때문에 간격을 줘야한다.

 

// transform.position = thingToFollow.transform.position + new Vector3 (0,0,-10);

 

 

'개인적인 공부 > Unity' 카테고리의 다른 글

Bool  (0) 2023.03.07
if 구문  (0) 2023.03.07
OnTriggerEnter2D()  (0) 2023.01.16
OnCollisionEnter2D()  (0) 2023.01.16
Colliders & Rigidbodies  (0) 2023.01.16