using UnityEngine; using System.Collections.Generic; public class ChasePlatformSpawner : MonoBehaviour { public GameObject platformPrefab; public int initialPlatforms = 5; public float platformLength = 10f; public Transform player; private float spawnZ = 0.0f; private float safeZone = 15.0f; private List activePlatforms = new List(); int counter = 0; void Start() { for (int i = 0; i < initialPlatforms; i++) SpawnPlatform(); } void Update() { if (player.position.z + safeZone < spawnZ) { SpawnPlatform(); DeletePlatform(); } } void SpawnPlatform() { //GameObject go = Instantiate(platformPrefab, new Vector3(0, 0, spawnZ), Quaternion.identity); GameObject go = Instantiate(platformPrefab, new Vector3(0, -counter*3.54f, spawnZ), platformPrefab.transform.rotation); activePlatforms.Add(go); spawnZ -= platformLength; counter++; } void DeletePlatform() { Destroy(activePlatforms[0]); activePlatforms.RemoveAt(0); } }