DNF-timer + next car button when finished

This commit is contained in:
magn9775
2024-04-26 18:21:02 +02:00
parent 69c51ec879
commit ef5c8e25a6
12 changed files with 736 additions and 239 deletions

View File

@@ -8,6 +8,7 @@ using UnityEditor.SearchService;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public int lapAmount;
@@ -20,6 +21,9 @@ public class GameManager : MonoBehaviour
public TextMeshProUGUI lapCounter;
public TextMeshProUGUI timeCounter;
public TextMeshProUGUI startTime;
public TextMeshProUGUI DNFTime;
public TextMeshProUGUI speedometer;
public GameObject nextCarbtn;
float DNFTimer = 0;
private bool hasCountedDown = false;
void Start()
@@ -51,6 +55,10 @@ public class GameManager : MonoBehaviour
StartGame();
}
for (int i = 0; i < players.Count(); i++)
{
GameObject player = players[i];
@@ -86,6 +94,10 @@ public class GameManager : MonoBehaviour
{
int checkpointsCollected = player.GetComponent<PlayerController>().checkpointsCollected;
carRB = player.GetComponent<RigidBody>();
carVel = (math.abs(carRB.velocity.x) + math.abs(carRB.velocity.y) + math.abs(carRB.velocity.z))*5;
speedometer.SetText(carVel.ToString());
if (checkpointsCollected == checkpoints.Count())
{
player.GetComponent<PlayerController>().checkpointsCollected = 0;
@@ -96,18 +108,7 @@ public class GameManager : MonoBehaviour
lapCounter.text = "Lap count: " + playerLaps[i] + "/" + lapAmount;
}
string strTimes =playerTimes[i].ToString();
int seconds = (int)MathF.Floor(playerTimes[i]);
int seperator = strTimes.IndexOf(",");
string miliseconds;
if (strTimes.Length < seperator + 4)
miliseconds = ",000";
else
miliseconds = strTimes.Substring(seperator, 4);
timeCounter.text = "Time: " + seconds + miliseconds;
timeCounter.text = "Time: " + (Mathf.Round(playerTimes[i]*1000)/1000).ToString();
}
if (playerLaps[i] > lapAmount)
@@ -120,6 +121,7 @@ public class GameManager : MonoBehaviour
else
playersFinished.Add(player.name + " (player)");
player.GetComponent<PlayerController>().enabled = false;
nextCarbtn.SetActive(true);
playerTimesStr[i] = playerTimes[i].ToString();
}
@@ -131,6 +133,7 @@ public class GameManager : MonoBehaviour
if (playersFinished.Count() > 0)
{
DNFTimer += Time.deltaTime;
DNFTime.text = "DNF timer: "+(Mathf.Round(60-DNFTimer)).ToString();
}
// race finished