using UnityEngine; // 발판을 생성하고 주기적으로 재배치하는 스크립트 public class PlatformSpawner : MonoBehaviour { public GameObject platformPrefab; // 생성할 발판의 원본 프리팹 public int count = 3; // 생성할 발판의 개수 public float timeBetSpawnMin = 1.25f; // 다음 배치까지의 시간 간격 최솟값 public float timeBetSpawnMax = 2.25f; // 다음 배치까지의 시간 간격 최댓값 private float timeBetSpawn; // 다음 배치까지의 시간 간격 public float yMin = -3.5f; // 배치할 위치의 최소 y값 public float yMax = 1.5f; // 배치할 위치의 최대 y값 private float xPos = 20f; // 배치할 위치의 x 값 private GameObject[] platforms; // 미리 생성한 발판들 private int currentIndex = 0; // 사용할 현재 순번의 발판 private Vector2 poolPosition = new Vector2(0, -25); // 화면 밖 위치 private float lastSpawnTime; // 마지막 배치 시점 void Start() { platforms = new GameObject[count]; for (int i = 0; i < count; i++) { // ❗ 오타 수정: Quaternion, identity → Quaternion.identity platforms[i] = Instantiate( platformPrefab, poolPosition, Quaternion.identity // 수정됨 ); } lastSpawnTime = 0f; // ❗ 오타 수정: timeBetspawn → timeBetSpawn timeBetSpawn = 0f; // 수정됨 } void Update() { if (GameManager.instance.isGameover) { return; } // ❗ 오타 수정: // lastspawntime → lastSpawnTime // timeBetspawn → timeBetSpawn if (Time.time >= lastSpawnTime + timeBetSpawn) // 수정됨 { lastSpawnTime = Time.time; timeBetSpawn = Random.Range(timeBetSpawnMin, timeBetSpawnMax); // ❗ 오타 수정: yMAX → yMax float yPos = Random.Range(yMin, yMax); // 수정됨 platforms[currentIndex].SetActive(false); platforms[currentIndex].SetActive(true); // ❗ yPos 스코프 문제 해결 (if 안에서 사용) platforms[currentIndex].transform.position = new Vector2(xPos, yPos); currentIndex++; if (currentIndex >= count) { currentIndex = 0; } } // 순서를 돌아가며 주기적으로 발판을 배치 } }