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

public class GameManager : MonoBehaviour
{
    [SerializeField] GameObject[] roadPrefab;
    bool isGameActive = true;
    GameObject player;

    public bool GetGameState()
    {
        return isGameActive;
    }

    public void SetGameState(bool gameState)
    {
        isGameActive = gameState;
    }

    void GenerateNewSegment()
    {
        if (isGameActive) {
            int randIndex = Random.Range(0, roadPrefab.Length);
            Instantiate(roadPrefab[randIndex],
                new Vector3(2.5f, -1.761234f, 37.7f),
                roadPrefab[randIndex].transform.rotation);
        }
    }

    // Start is called before the first frame update
    void Start()
    {
        InvokeRepeating("GenerateNewSegment", 5.0f, 4.0f);
        player = GameObject.Find("Player");
    }

    // Update is called once per frame
    void Update()
    {
        if(!isGameActive)
        {
            player.GetComponent<PlayerController>().enabled = false;
        }
    }
}
