game manager stuff

This commit is contained in:
2024-04-26 10:08:24 +02:00
parent 55d93fe847
commit 1aa9c743cd
7 changed files with 125 additions and 53 deletions

View File

@@ -1,14 +1,17 @@
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 string[] playersFinished;
[HideInInspector] public List<string> playersFinished;
[HideInInspector] public List<string> playerTimes;
int[] playerLaps;
void Start()
@@ -25,11 +28,13 @@ public class GameManager : MonoBehaviour
// Update is called once per frame
void Update()
{
print("playersfinished: " + playersFinished.Count());
for (int i = 0; i < players.Count(); i++)
{
GameObject player = players[i];
if (playersFinished.Contains(player.name))
if (playersFinished.Contains(player.name) || playersFinished.Contains(player.name + " (player)"))
continue;
bool isAI = true;
@@ -59,13 +64,27 @@ public class GameManager : MonoBehaviour
if (playerLaps[i] > lapAmount)
{
player.GetComponent<Rigidbody>().isKinematic = true;
playersFinished.Append(player.name);
if (isAI)
{
playersFinished.Add(player.name);
player.GetComponent<AgentController>().enabled = false;
}
else
playersFinished.Add(player.name + " (player)");
player.GetComponent<PlayerController>().enabled = false;
print("\nPlayers finished:");
foreach (string pp in playersFinished)
print(pp);
float time = Random.Range(15f, 40f);
playerTimes.Add(time.ToString());
}
}
// race finished
if (playersFinished.Count() == players.Count())
{
SceneManager.LoadScene("WinScreen");
}
}
}