Background

2025. 5. 13. 10:43개발일지/Journey to West

배경의 무한이동처럼 보이게 하기

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

public class Background : MonoBehaviour
{
    public float scrollSpeed;
    private Vector2 startPosition;
    public float repeatHeight;

    // Start is called before the first frame update
    void Start()
    {
        startPosition = transform.position;
    }

    // Update is called once per frame
    void Update()
    {
        float newPosition = Mathf.Repeat(Time.time * scrollSpeed, repeatHeight);
        transform.position = startPosition + Vector2.down * newPosition;

    }
}

RepeatHeight 는 이미지의 높이에 맞게 설정해 줘야 한다.

 

결과

 

 

'개발일지 > Journey to West' 카테고리의 다른 글

오브젝트 풀링  (1) 2025.05.16