using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// Base class game controller.
///
public class GameController :MonoBehaviour
{
[SerializeField] KeyCode NextCarKey = KeyCode.N;
[SerializeField] UnityEngine.UI.Button NextCarButton;
public static GameController Instance;
public GameObject PlayerCar;
public GameObject cam;
public static bool RaceIsStarted { get { return true; } }
public static bool RaceIsEnded { get { return false; } }
//PlayerController m_PlayerCar;
//List Cars = new List();
public List cars;
int CurrentCarIndex = 0;
protected virtual void Awake ()
{
Instance = this;
// foreach (var car in cars)
// {
// var userControl = car.GetComponent();
// var audioListener = car.GetComponent();
// if (userControl == null)
// {
// userControl = car.gameObject.AddComponent ();
// }
// if (audioListener == null)
// {
// audioListener = car.gameObject.AddComponent ();
// }
// userControl.enabled = false;
// audioListener.enabled = false;
// }
// cars[CurrentCarIndex].GetComponent().enabled = true;
// cars[CurrentCarIndex].GetComponent().enabled = true;
}
void Update ()
{
if (Input.GetKeyDown (NextCarKey))
{
NextCar ();
}
}
private void NextCar ()
{
// cars[CurrentCarIndex].GetComponent ().enabled = false;
// cars[CurrentCarIndex].GetComponent ().enabled = false;
CurrentCarIndex = LoopClamp (CurrentCarIndex + 1, 0, cars.Count);
// cars[CurrentCarIndex].GetComponent().enabled = true;
// cars[CurrentCarIndex].GetComponent().enabled = true;
PlayerCar = cars[CurrentCarIndex];
cam.GetComponent().getCar(PlayerCar);
print(PlayerCar.name);
}
public static int LoopClamp (int value, int minValue, int maxValue)
{
while (value < minValue || value >= maxValue)
{
if (value < minValue)
{
value += maxValue - minValue;
}
else if (value >= maxValue)
{
value -= maxValue - minValue;
}
}
return value;
}
}