배경에 콜라이더를 넣었더니 플레이어와 충돌 현상이 일어남
배경에 콜라이더를 삭제하고
스크립트를 각각 부착하고 X축의 길이를 숫자로 넣어줌
공통 이동 스크립트
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Scrolling : MonoBehaviour
{
public float speed;
void Update()
{
// if (!GameManager.instance.isGameOver) 게임오버가 아니면
//게임오브젝트를 왼쪽으로 움직임
this.transform.Translate(Vector3.left * speed * Time.deltaTime);
}
}
무한 반복 스크립트
벽 루프
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BackgroundLoop : MonoBehaviour
{
private float width=17.88f; //배경의 가로길이
private void Awake()
{
//가로길이를 측정
// BoxCollider2D boxCollider = GetComponent<BoxCollider2D>();
// width = boxCollider.size.x;
//Debug.Log(width);
}
void Update()
{
//현재위치가 width 이상 됐을때 위치 재배치
if (transform.position.x <= -width)
{
RePosition();
}
}
private void RePosition()
{
//위치를 재배치
//현재위치에서 가로길이 2배만큼 오른쪽으로 이동
Vector2 offset = new Vector2(this.width * 2, 0);
this.transform.position = (Vector2)this.transform.position + offset;
}
}
불꽃 루프
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FireBgLoop : MonoBehaviour
{
private float width = 26.32f; //배경의 가로길이
private void Awake()
{
//가로길이를 측정
// BoxCollider2D boxCollider = GetComponent<BoxCollider2D>();
// width = boxCollider.size.x;
//Debug.Log(width);
}
void Update()
{
//현재위치가 width 이상 됐을때 위치 재배치
if (transform.position.x <= -width)
{
RePosition();
}
}
private void RePosition()
{
//위치를 재배치
//현재위치에서 가로길이 2배만큼 오른쪽으로 이동
Vector2 offset = new Vector2(this.width * 2, 0);
this.transform.position = (Vector2)this.transform.position + offset;
}
}
'게임프로젝트 > 쿠키런 모작' 카테고리의 다른 글
타일맵 랜덤 생성값 저장하기(2) (0) | 2024.03.30 |
---|---|
타일맵 제작 (0) | 2024.03.29 |
쿠키런 모작 진행 과정 (0) | 2024.03.29 |
타일맵 랜덤 생성값 저장하기(2) (0) | 2024.03.26 |
R&D 타일맵 랜덤 무한 생성(2) 오브젝트 풀링으로 수정 (0) | 2024.03.26 |