diff --git a/Assets/Scripts/Car/Car.cs b/Assets/Scripts/Car/Car.cs index 3093f15..646eece 100644 --- a/Assets/Scripts/Car/Car.cs +++ b/Assets/Scripts/Car/Car.cs @@ -8,11 +8,11 @@ public float roadPositon = 0f, speed = 0f, brakingAcceleration, acceleration, airResistance, t; private int roadIndex = 0; private GameObject gameObject; - private Config config; + public Config config; public Vector3 position, direction; public bool isAlive = true; private CarData carData; - float brakingTime, brakingDistance; + private float brakingTime, brakingDistance; public Car(Route route, Transform parent, Config config) { this.route = route; diff --git a/Assets/Scripts/Car/Car.cs b/Assets/Scripts/Car/Car.cs index 3093f15..646eece 100644 --- a/Assets/Scripts/Car/Car.cs +++ b/Assets/Scripts/Car/Car.cs @@ -8,11 +8,11 @@ public float roadPositon = 0f, speed = 0f, brakingAcceleration, acceleration, airResistance, t; private int roadIndex = 0; private GameObject gameObject; - private Config config; + public Config config; public Vector3 position, direction; public bool isAlive = true; private CarData carData; - float brakingTime, brakingDistance; + private float brakingTime, brakingDistance; public Car(Route route, Transform parent, Config config) { this.route = route; diff --git a/Assets/Scripts/Car/CarData.cs b/Assets/Scripts/Car/CarData.cs index dcc16a9..073b9bc 100644 --- a/Assets/Scripts/Car/CarData.cs +++ b/Assets/Scripts/Car/CarData.cs @@ -4,15 +4,20 @@ public class CarData : MonoBehaviour { public Car car; + private float lifetime = 0f; void Start() { } public void Update() { car.step(Time.deltaTime); + lifetime += Time.deltaTime; if (car.isAlive) { transform.position = car.position; transform.forward = car.direction; + } else { + car.config.totalTravelTime += lifetime; + car.config.totalCars++; } } diff --git a/Assets/Scripts/Car/Car.cs b/Assets/Scripts/Car/Car.cs index 3093f15..646eece 100644 --- a/Assets/Scripts/Car/Car.cs +++ b/Assets/Scripts/Car/Car.cs @@ -8,11 +8,11 @@ public float roadPositon = 0f, speed = 0f, brakingAcceleration, acceleration, airResistance, t; private int roadIndex = 0; private GameObject gameObject; - private Config config; + public Config config; public Vector3 position, direction; public bool isAlive = true; private CarData carData; - float brakingTime, brakingDistance; + private float brakingTime, brakingDistance; public Car(Route route, Transform parent, Config config) { this.route = route; diff --git a/Assets/Scripts/Car/CarData.cs b/Assets/Scripts/Car/CarData.cs index dcc16a9..073b9bc 100644 --- a/Assets/Scripts/Car/CarData.cs +++ b/Assets/Scripts/Car/CarData.cs @@ -4,15 +4,20 @@ public class CarData : MonoBehaviour { public Car car; + private float lifetime = 0f; void Start() { } public void Update() { car.step(Time.deltaTime); + lifetime += Time.deltaTime; if (car.isAlive) { transform.position = car.position; transform.forward = car.direction; + } else { + car.config.totalTravelTime += lifetime; + car.config.totalCars++; } } diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index b80fc7d..2da6402 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -12,6 +12,8 @@ public Mesh carMesh; public Material carMaterial; public float power = 1000f; + public float totalTravelTime = 0f; + public int totalCars = 0; public void click(Mode mode, int index) { this.mode = Mode.ClickButton;