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

48 lines
1.3 KiB
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() {
Debug.LogError("SpaceRace!");
Debug.LogError("WSAD - Strafe");
Debug.LogError("Mouse 1 - Thrust");
Debug.LogError("Mouse 2 - Decelerate");
Debug.LogError("Space - Respawn");
Debug.LogError("F10 - Exit");
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.LogError("Lap Complete " + other.gameObject.name);
double lapTime = Time.timeAsDouble - lapStart;
lapTimes.Add(lapTime);
TimeSpan lapSpan = TimeSpan.FromSeconds(lapTime);
Debug.LogError("Time " + lapSpan.ToString("c"));
}
void OnTriggerExit(Collider other) {
Debug.LogError("Starting Lap " + other.gameObject.name);
lapStart = Time.timeAsDouble;
}
}