Added respawn for AI, Game manager keeps track of laps

This commit is contained in:
2024-04-24 10:11:56 +02:00
parent f06887db7e
commit 6db70114b0
7 changed files with 369 additions and 1115 deletions

View File

@@ -24,16 +24,40 @@ public class GameManager : MonoBehaviour
// Update is called once per frame
void Update()
{
foreach (GameObject player in players)
for (int i = 0; i < players.Count(); i++)
{
try
GameObject player = players[i];
bool isAI = true;
if (player.GetComponent<PlayerController>().enabled)
isAI = false;
if (isAI)
{
bool isFinished = player.GetComponent<AgentController>().isFinished;
if (isFinished)
{
player.GetComponent<AgentController>().isFinished = false;
playerLaps[i] += 1;
}
}
else
{
int checkpointsCollected = player.GetComponent<PlayerController>().checkpointsCollected;
if (checkpointsCollected == checkpoints.Count())
{
player.GetComponent<PlayerController>().checkpointsCollected = 0;
playerLaps[i] += 1;
}
}
catch
if (playerLaps[i] > lapAmount)
{
int checkpointsCollected = player.GetComponent<AgentController>().checkpointsCollected;
player.GetComponent<Rigidbody>().isKinematic = true;
}
}
}
}