MiniGames/Assets/Scripts/ChaseOn/ChasePlatformSpawner.cs

45 lines
1.1 KiB
C#
Raw Normal View History

2025-07-30 01:38:12 +05:00
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<GameObject> activePlatforms = new List<GameObject>();
2025-08-06 19:14:48 +05:00
int counter = 0;
2025-07-30 01:38:12 +05:00
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);
2025-08-06 19:14:48 +05:00
GameObject go = Instantiate(platformPrefab, new Vector3(0, -counter*3.54f, spawnZ), platformPrefab.transform.rotation);
2025-07-30 01:38:12 +05:00
activePlatforms.Add(go);
spawnZ -= platformLength;
2025-08-06 19:14:48 +05:00
counter++;
2025-07-30 01:38:12 +05:00
}
void DeletePlatform()
{
Destroy(activePlatforms[0]);
activePlatforms.RemoveAt(0);
}
}