Camera Follow

Kyu hyunSung·2025년 7월 24일

How to Make Camera Follow In UNITY 2D

Code

using UnityEngine;

public class PlayerCamera : MonoBehaviour
{

    public float FollowSpeed = 2f; // Speed at which the camera follows the player
    public Transform target;

    public float yOffset = -1f; // Offset for the camera's y position

   
    void Update()
    {
        Vector3 newPos = new Vector3(target.position.x, target.position.y + yOffset, -10f);
        transform.position = Vector3.Lerp(transform.position, newPos, FollowSpeed * Time.deltaTime);
    }
}
profile
디지털 치매 예방

0개의 댓글