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; } } public TextMeshPro speedometer; public List cars; int CurrentCarIndex = 0; private List finished; void Start() { finished=gameObject.GetComponent().playersFinished; if (speedometer == null) { speedometer = new TextMeshPro(); } if (carRB == null) { carRB = GetComponent(); } } public void Update () { if (Input.GetKeyDown (NextCarKey)) { NextCar (); } carVel = (math.abs(carRB.velocity.x) + math.abs(carRB.velocity.y) + math.abs(carRB.velocity.z))*5; //print(carVel); speedometer.SetText(carVel.ToString()); } public void NextCar() { for (int i = 0; i < cars.Count; i++) { if (finished.Contains(cars[i].name)) { cars.Remove(cars[i]); } } CurrentCarIndex = LoopClamp (CurrentCarIndex + 1, 0, cars.Count); PlayerCar = cars[CurrentCarIndex]; cam.GetComponent().getCar(PlayerCar); } 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; } }