Alright, I want to set some ‘win conditions’ on the levels of my game.
Until now I have just used an arbitrary score, and when you exceed the score, it loads the next scene. That was simple enough. But now I want to change things up for later levels, and I want you to hit a certain target or SET OF TARGETS and exceed a score (it could just as well be limited to hitting certain targets, for our purposes here).
Conceptually, it makes sense. I want to have a bool on these targets, that switch from false to true, after they have been hit. And to load the next scene, none should pass as false (all targets pass as hit/true).
I have the array set up, I think. But how do I access the bool value, in the script, on those target objects?
I am looking for objects that have the script ‘Target’ on them. All will have it, all will have the bool set to true, as default, and then the actual targets I will set to false in the Inspector (so that I can have different targets, and even a different number of targets, on each level).
GameObject[] targets = GameObject.FindObjectsOfType(typeof(Target)) as GameObject[];
Now I have a bool on the script, Target, targetHit, and on collision it obviously changes to true.
But how do I check that bool for all targets in my GameManager script?
foreach (GameObject target in targets)
{
if(target.targetHit == true)
{
}
}
That is what I was hoping what would work, but I am getting an error. Clearly I am missing a step, where I tell the script how to check the targets for the bool value, targetHit.