game manager stuff
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user