fix all kinds of timer problems
This commit is contained in:
1 parent
bbcb434cd0
commit
558671a75e
5 files changed
+62
-22
No files matched your search
+12
-4
@@ -23,7 +23,7 @@ public readonly struct SectorTime {
|
||||
public double Value { get; }
|
||||
public SectorColour Colour { get; }
|
||||
|
||||
public override string ToString() => $"{Sector} {Value:0.000}";
|
||||
public override string ToString() => $"{Value:0.000}";
|
||||
|
||||
public string ColourClass() => Colour switch {
|
||||
SectorColour.Green => "green",
|
||||
@@ -55,21 +55,25 @@ public class Timing: MonoBehaviour {
|
||||
public bool timerEnabled;
|
||||
|
||||
public double sectorTime;
|
||||
public double lapTime;
|
||||
double sectorStart;
|
||||
Sector[] sectors;
|
||||
double lapStart;
|
||||
public Sector[] sectors;
|
||||
|
||||
void Awake() {
|
||||
lapTimes = new();
|
||||
sectorTimes = new List<SectorTime>();
|
||||
sectorStart = 0.0;
|
||||
sectorTime = 0.0;
|
||||
sectors = GetComponentsInChildren<Sector>();
|
||||
sectors = GetComponentsInChildren<Sector>().OrderBy(s => s.sector).ToArray();
|
||||
Debug.Log("Track Sector Count - " + sectors.Length);
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if (timerEnabled)
|
||||
if (timerEnabled) {
|
||||
sectorTime = Time.timeAsDouble - sectorStart;
|
||||
lapTime = Time.timeAsDouble - lapStart;
|
||||
}
|
||||
}
|
||||
|
||||
public void StartTimer() {
|
||||
@@ -81,6 +85,7 @@ public class Timing: MonoBehaviour {
|
||||
Debug.Log("Started Timer");
|
||||
|
||||
timerEnabled = true;
|
||||
lapStart = Time.timeAsDouble;
|
||||
sectorStart = Time.timeAsDouble;
|
||||
}
|
||||
|
||||
@@ -88,6 +93,7 @@ public class Timing: MonoBehaviour {
|
||||
sectorTimes = new List<SectorTime>();
|
||||
timerEnabled = false;
|
||||
sectorTime = 0;
|
||||
lapTime = 0;
|
||||
Debug.Log("Timer Stopped");
|
||||
|
||||
EndLap();
|
||||
@@ -115,6 +121,8 @@ public class Timing: MonoBehaviour {
|
||||
SectorTime s = new SectorTime(sector, sTime);
|
||||
sectorTimes.Add(s);
|
||||
|
||||
sectorStart = Time.timeAsDouble;
|
||||
|
||||
if (sectorTimes.Count == sectors.Length) {
|
||||
EndLap();
|
||||
NextLap();
|
||||
|
||||
Reference in new issue
Block a user