diff options
Diffstat (limited to 'Assets/Scripts/ColumnPool.cs')
-rw-r--r-- | Assets/Scripts/ColumnPool.cs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Assets/Scripts/ColumnPool.cs b/Assets/Scripts/ColumnPool.cs new file mode 100644 index 0000000..34d10b8 --- /dev/null +++ b/Assets/Scripts/ColumnPool.cs @@ -0,0 +1,47 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ColumnPool : MonoBehaviour { + + public int columnPoolSize = 5; + public GameObject columnPrefab; + public float spawnRate = 4f; + public float columnMin = -1f; + public float columnMax = 3.5f; + + private GameObject[] columns; + private Vector2 objectPoolPosition = new Vector2(-15f, 25f); + private float timeSinceLastSpawned; + private float spawnXPosition = 10f; + private int currentColumn = 0; + + + // Use this for initialization + void Start () + { + columns = new GameObject[columnPoolSize]; + for (int i = 0; i < columnPoolSize; i++) + { + columns[i] = (GameObject)Instantiate(columnPrefab, objectPoolPosition, Quaternion.identity); + } + } + + // Update is called once per frame + void Update () + { + timeSinceLastSpawned += Time.deltaTime; + + if (GameControl.instance.gameOver == false && timeSinceLastSpawned >= spawnRate) + { + timeSinceLastSpawned = 0; + float spawnYPosition = Random.Range(columnMin, columnMax); + columns[currentColumn].transform.position = new Vector2(spawnXPosition, spawnYPosition); + currentColumn++; + if (currentColumn >= columnPoolSize) + { + currentColumn = 0; + } + } + } +} |