Files
spacerace/Assets/StartFinishLine.cs
T
2023-07-04 18:18:59 +10:00

41 lines
990 B
C#

using System;
using System.Collections.Generic;
using UnityEngine;
public class StartFinishLine : MonoBehaviour {
ShipControls ship;
// timing...
List<double> lapTimes;
List<double> sectorTimes;
double lapStart;
void Awake() {
ship = GetComponent<ShipControls>();
lapTimes = new List<double>();
sectorTimes = new List<double>();
}
void OnTriggerEnter(Collider other) {
// our timer is not running
// either because we haven't started racing yet
// or we respawned
if (lapStart == 0)
return;
// we are completing a lap
Debug.Log("Lap Complete");
double lapTime = Time.timeAsDouble - lapStart;
lapTimes.Add(lapTime);
TimeSpan lapSpan = TimeSpan.FromSeconds(lapTime);
Debug.Log("Time " + lapSpan.ToString("c"));
}
void OnTriggerExit(Collider other) {
Debug.Log("Starting Lap");
lapStart = Time.timeAsDouble;
}
}