종스크롤 2D 슈팅게임 배경 스크롤링
Unity3D 2023. 2. 5. 20:04반응형
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class BgScroller : MonoBehaviour
{
public float speed;
public Transform[] sprites;
private Queue<int> q = new Queue<int>();
private void Awake()
{
for (int i = sprites.Length-1; i >= 0; --i)
q.Enqueue(i);
}
void Update()
{
var curPos = this.transform.position;
var nextPos = Vector3.down * this.speed * Time.deltaTime;
this.transform.position = curPos + nextPos;
if (this.sprites[q.Peek()].position.y <= -12)
{
//0 -> 2 -> 1
//1 -> 0 -> 2
//2 -> 1 -> 0
this.sprites[q.Peek()].transform.localPosition = this.sprites[q.Last()].localPosition + Vector3.up * 12;
q.Enqueue(this.q.Dequeue());
}
}
}
반응형
'Unity3D' 카테고리의 다른 글
ASTC 와 ETC2 (0) | 2023.07.04 |
---|---|
unity object pooling (0) | 2023.02.05 |
온디맨드 렌더링을 이용한 모바일 성능 개선 (0) | 2022.11.28 |
유니티 스크립트 Missing 한번에 지우기 (SelectGameObjectsWithMissingScripts) (0) | 2022.05.10 |
Load font from mobile device and assign as fallback TMP_FontAsset (0) | 2022.05.03 |