I have an array of objects of the class Target, and I have a for loop to check a statement on each of them. What I need to do is check if all of the Target scripts are shot down, which I can do by checking the value of the boolean property hasShotDown. Then, if all the Target objects in the array return true for hasShotDown, the game should end, by stopping the timer object.
public Timer timer;
public Target[] targets;
private void Start() {
targets = gameObject.GetComponents<Target>();
}
private void OnTriggerEnter(Collider other) {
if (other.gameObject.layer == 9) {
foreach (Target obj in targets) {
if (obj.hasShotDown) {
timer.StopTimer();
Debug.Log("Stopped Timer and Ended game");
}
}
}
}
Timer is a reference to another class, which can stop, start and display the timer. Target is another class, which holds hasShotDown. All help is appreciated, let me know if more info is needed.