public void SetDroneAmount(int amount) { if (amount < 0) { throw new ArgumentException("Amount may not be less than zero."); } if (amount == DroneCount) { return; } if (amount > drones.Count) { for (int toBeAdded = amount - drones.Count; toBeAdded > 0; toBeAdded--) { GameObject droneCopy = Instantiate(PrototypeDrone.gameObject); droneCopy.transform.position = startPosition; droneCopy.transform.rotation = startRotation; DroneController controllerCopy = droneCopy.GetComponent <DroneController>(); drones.Add(new MarsDrone(controllerCopy, 1)); droneCopy.SetActive(true); } } else if (amount < drones.Count) { for (int toBeRemoved = drones.Count - amount; toBeRemoved > 0; toBeRemoved--) { MarsDrone last = drones[drones.Count - 1]; drones.RemoveAt(drones.Count - 1); Destroy(last.Drone.gameObject); } } }
void Update() { for (int i = 0; i < drones.Count; i++) { MarsDrone drone = drones[i]; if (drone.Drone.enabled) { drone.Drone.CurrentCompletionReward = GetCompletePerc(drone.Drone, ref drone.CheckpointIndex); if (BestDrone == null || drone.Drone.CurrentCompletionReward >= BestDrone.CurrentCompletionReward) { BestDrone = drone.Drone; } else if (SecondBestDrone == null || drone.Drone.CurrentCompletionReward >= SecondBestDrone.CurrentCompletionReward) { SecondBestDrone = drone.Drone; } } } }