This commit is contained in:
magn9775
2024-04-26 15:58:44 +02:00
parent 4dbfc5542c
commit 69c51ec879
7 changed files with 205 additions and 16 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using Unity.VisualScripting;
using UnityEditor.SearchService;
using UnityEngine;
using UnityEngine.SceneManagement;
@@ -18,7 +19,9 @@ public class GameManager : MonoBehaviour
int[] playerLaps;
public TextMeshProUGUI lapCounter;
public TextMeshProUGUI timeCounter;
public TextMeshProUGUI startTime;
float DNFTimer = 0;
private bool hasCountedDown = false;
void Start()
{
// reset laps
@@ -33,8 +36,8 @@ public class GameManager : MonoBehaviour
for (int i = 0; i < players.Count(); i++)
{
playerTimes[i] = 0.00000001f;
playerTimesStr[i] = "0";
playerTimes[i] = 0.00000000000f;
playerTimesStr[i] = "1000000";
}
DontDestroyOnLoad(gameObject);
@@ -43,6 +46,11 @@ public class GameManager : MonoBehaviour
// Update is called once per frame
void Update()
{
if (!hasCountedDown)
{
StartGame();
}
for (int i = 0; i < players.Count(); i++)
{
GameObject player = players[i];
@@ -56,9 +64,10 @@ public class GameManager : MonoBehaviour
{
return;
}
if (hasCountedDown)
{
playerTimes[i] += Time.deltaTime;
}
bool isAI = true;
if (player.GetComponent<PlayerController>().enabled)
isAI = false;
@@ -116,6 +125,8 @@ public class GameManager : MonoBehaviour
}
}
//DNF
if (playersFinished.Count() > 0)
{
@@ -123,7 +134,7 @@ public class GameManager : MonoBehaviour
}
// race finished
if (playersFinished.Count() == players.Count() || DNFTimer > 10)
if (playersFinished.Count() == players.Count() || DNFTimer > 60)
{
// sort array
float[] fTimes = new float[players.Count()];
@@ -148,10 +159,45 @@ public class GameManager : MonoBehaviour
}
}
for (var i = 0; i < players.Count();i++)
{
if (!playersFinished.Contains(players[i].name) && !playersFinished.Contains(players[i].name + " (player)")){
playersFinished.Add(players[i].name);
}
}
SceneManager.LoadScene("WinScreen");
}
}
private float sTime = 5;
private void StartGame(){
sTime -= Time.deltaTime;
startTime.text = (Mathf.Round(sTime*10)/10).ToString();
if (sTime/60 <= 5 && sTime/60 >= 0)
{
for (var i = 0; i < players.Count(); i++)
{
players[i].GetComponent<Rigidbody>().isKinematic = true;
}
} else if (sTime/60 < 0) {
for (var i = 0; i < players.Count(); i++)
{
players[i].GetComponent<Rigidbody>().isKinematic = false;
}
startTime.text = "";
hasCountedDown=true;
}
}
}