timer thing probably works

This commit is contained in:
2024-04-26 13:25:39 +02:00
parent 2fe54fe26e
commit 8744c617fc
3 changed files with 18 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@@ -22,6 +23,7 @@ public class GameManager : MonoBehaviour
// reset laps
playerLaps = new int[players.Count()];
playerTimes = new float[players.Count()];
playerTimesStr = new string[players.Count()];
for (int i = 0; i < playerLaps.Count(); i++)
{
@@ -30,7 +32,8 @@ public class GameManager : MonoBehaviour
for (int i = 0; i < players.Count(); i++)
{
playerTimes[i] = 0;
playerTimes[i] = 0.00000001f;
playerTimesStr[i] = "DNF";
}
DontDestroyOnLoad(gameObject);
@@ -82,7 +85,18 @@ public class GameManager : MonoBehaviour
lapCounter.text = "Lap count: " + playerLaps[i];
}
timeCounter.text = "Time: " + playerTimes[i].ToString();
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;
}
if (playerLaps[i] > lapAmount)
@@ -104,7 +118,6 @@ public class GameManager : MonoBehaviour
// race finished
if (playersFinished.Count() == players.Count())
{
// if not finished DNF //TODO
SceneManager.LoadScene("WinScreen");
}