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

public class Road : MonoBehaviour
{
    private Cube[] gameObjects;
    public Transform player;
    public List<hole> holes;
    int i = 0;
    public bool isin;
    public TextMesh text;
    private void Start()
    {
        
    }
    // Update is called once per frame
    void Update()
    {
        foreach (Cube obj in GetComponentsInChildren<Cube>())
        {
            if (obj.transform.position.z - player.transform.position.z < 35)
            {
                if (obj.transform.position.y < 0)
                    obj.transform.position -= Vector3.down * 5 * Time.deltaTime;
                else
                    obj.transform.position = new Vector3(obj.transform.position.x, 0, obj.transform.position.z);
            }
        }
        if (isin)
        {
            i = 0;
            while (i < holes.Count)
            {
                if (holes[i].isrun)
                {
                    player.GetComponent<player>().holeThatIWillControll = holes[i];
                    break;
                }
                else
                {
                    holes[i].toORIG();
                    Destroy(holes[i]);
                    holes.RemoveAt(i);
                }
                
                i++;
            }
        }
        i = 0;
        while (i < holes.Count)
        {
            if (holes[i].transform.position.z - player.transform.position.z < 0)
            {
                player.gameObject.GetComponent<player>().falling = true;
            }
            i++;
        }
    }
    public void changeText(string t)
    {
        text.text = t;
    }
}
