using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEditor.SearchService; using UnityEngine; using UnityEngine.SceneManagement; public class GameManager : MonoBehaviour { public int lapAmount; public GameObject[] checkpoints; public GameObject[] players; [HideInInspector] public List playersFinished; [HideInInspector] public List playerTimes; int[] playerLaps; void Start() { // reset laps playerLaps = new int[players.Count()]; for (int i = 0; i < playerLaps.Count(); i++) { playerLaps[i] = 1; } DontDestroyOnLoad(gameObject); } // Update is called once per frame void Update() { print("playersfinished: " + playersFinished.Count()); for (int i = 0; i < players.Count(); i++) { GameObject player = players[i]; try { if (playersFinished.Contains(player.name) || playersFinished.Contains(player.name + " (player)")) continue; } catch { return; } bool isAI = true; if (player.GetComponent().enabled) isAI = false; if (isAI) { bool isFinished = player.GetComponent().isFinished; if (isFinished) { player.GetComponent().isFinished = false; playerLaps[i] += 1; } } else { int checkpointsCollected = player.GetComponent().checkpointsCollected; if (checkpointsCollected == checkpoints.Count()) { player.GetComponent().checkpointsCollected = 0; playerLaps[i] += 1; } } if (playerLaps[i] > lapAmount) { if (isAI) { playersFinished.Add(player.name); player.GetComponent().enabled = false; } else playersFinished.Add(player.name + " (player)"); player.GetComponent().enabled = false; float time = Random.Range(15f, 40f); playerTimes.Add(time.ToString()); } } // race finished if (playersFinished.Count() == players.Count()) { SceneManager.LoadScene("WinScreen"); } } }