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

public class gnrRoad : MonoBehaviour
{
    public List<GameObject> roads;
    public int rand;
    int place;
    GameObject road;
    GameObject lastRoad;
    GameObject lastlastRoad;
    int i;
    // Start is called before the first frame update
    void Start()
    {
        place = 36;
    }

    // Update is called once per frame
    private void Update()
    {
        rand = Random.Range(0, 2);
    }
    void FixedUpdate()
    {
        if ((int)transform.position.z == place - 36)
        {
            if (lastlastRoad)
            {
                Destroy(lastlastRoad);
            }
            if (lastRoad)
            {
                lastlastRoad = lastRoad;

            }
            if (road)
            {
                lastRoad = road;
            }
            
            road = Instantiate<GameObject>(roads[rand]) as GameObject;
            i++;
            road.GetComponent<Road>().changeText(i.ToString());
            road.transform.position = new Vector3(0, -10, place);
            road.GetComponent<Road>().player = transform;
            if (lastRoad) lastRoad.GetComponent<Road>().isin = true;

            /*
            if (lastRoad)
            {
                Destroy(lastRoad);
            }

            road = Instantiate<GameObject>(roads[rand]) as GameObject;
            road.transform.position = new Vector3(0, -10, place);
            road.GetComponent<Road>().player = transform;
            lastRoad.GetComponent<Road>().isin = true;*/
            place += GameState.startingPose;

        }
    }
}
