using UnityEngine;

public class GroundSpawner : MonoBehaviour
{
    public static GroundSpawner instance;
    public GameObject[] grounds;
    public Vector2 nextSpawnPos;
    private int index;
    public int numberOfGrounds = 3;

    private void Awake()
    {
        if (instance == null) {
            instance = this;
        }
        else {
            Destroy(this);
        }
    }

    void Start()
    {
        for (int i = 0; i < numberOfGrounds; i++)
        {
            SpawnGround();
        }
    }

    public void SpawnGround() {
        index = Random.Range(0, grounds.Length);
        GameObject tempGround = Instantiate(grounds[index], nextSpawnPos, Quaternion.identity);
        nextSpawnPos = tempGround.transform.GetChild(1).transform.position;
    }
}
