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

public class CarGenerator : MonoBehaviour
{
    public List<GameObject> VehiclePrefabs;
    public GameObject PowerUpPrefab;

    private float NextCarCreateTime;
    private float NextPowerUpCreateTime;
	private float Difficulty = 0.04f;
	public float NewCarSpeed;

    private void Start()
    {
        NextCarCreateTime = Time.time;
        NextPowerUpCreateTime = Time.time;
    }

    private void Update()
    {
        if (NextCarCreateTime <= Time.time)
        {
            NextCarCreateTime = Time.time + (Difficulty * 5);
			int lRndCar = Random.Range(0, VehiclePrefabs.Count);
            GameObject lNewVehicle = Instantiate(VehiclePrefabs[lRndCar]);
            float lYPosition = Random.Range(-8.5f, 8.5f);
            lNewVehicle.transform.position = new Vector3(100, lYPosition, 1);
			lNewVehicle.GetComponent<VehicleController>().VehicleSpeed = NewCarSpeed;
        }

        if (NextPowerUpCreateTime <= Time.time)
        {
            NextPowerUpCreateTime = Time.time + (Difficulty * 15);
            GameObject lNewPowerUp = Instantiate(PowerUpPrefab);
            float lYPosition = Random.Range(-8.5f, 8.5f);
            lNewPowerUp.transform.position = new Vector3(100, lYPosition, 0.4f);
            lNewPowerUp.GetComponent<VehicleController>().VehicleSpeed = NewCarSpeed;
        }
    }
}
