using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class platformspawner : MonoBehaviour
{
    public GameObject platform;
    public Transform lastplatform;
    Vector3 lastpos;
    Vector3 newpos;

    bool stop;
  
    // Start is called before the first frame update
    void Start()
    {
        lastpos = lastplatform.position;
        StartCoroutine( Spawnplatforn());
    }

    // Update is called once per frame
    void Update()
    {
        
    }
     void genratepos()
    {
        newpos = lastpos;
        int rand = Random.Range(0, 2);
        if (rand > 0)
        {
            newpos.x += 2f;

        }
        else
        {
            newpos.z += 2f;
        }
    }
    IEnumerator Spawnplatforn()
    {
        while (!stop)
        {
            genratepos();
            Instantiate(platform, newpos, Quaternion.identity);
            lastpos = newpos;
            yield return new WaitForSeconds(0.2f);
        }
    }



}
