Super Kawaii Cute Cat Kaoani
본문 바로가기
🎮 취미/Unity

유니티 쯔꾸르 게임 만들기 4 (인프런)

by wonee1 2023. 7. 1.
728x90

<제4강 카메라 움직이기>
 
 
 
lerp는 a값과 b값 사이의 선형 보간으로 중간 값을 리턴한다.
ex)(1,10,0.5f)=5 (5,10,0.5)
this.transfor m.position=Vector3.Lerp(this.transform.position,targetPosition,moveSpeed*Time.deltaTime) 
현재 자기 자신의 위치에서 대상의 위치까지 delta의 속도로 이동하는 것 
deltaTime 1초에 실행되는 프레임의 역수 , 1초에 60프레임이 실행되면 60분의 1 값을 가짐 즉 1초에 movespeed만큼 이동한다 
 

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

public class CameraManager : MonoBehaviour
{
    public GameObject target;//카메라가 따라갈 대상 
    public float moveSpeed; //카메라가 얼마나 빠른 속도로
    private Vector3 targetPosition;//대상의 현재 위치 값 

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (target.gameObject != null)
        {
            targetPosition.Set(target.transform.position.x, target.transform.position.y, this.transform.position.z);//this는 카메라를 가리킴 (카메라는 고유값을 계속갖고있어야함)
            this.transform.position = Vector3.Lerp(this.transform.position, targetPosition, moveSpeed * Time.deltaTime);

        }
    }
}

 
 
 

 
 
 
 
 

 

728x90