Check to see if any bool instance is true?

Hello all,

Literally all day I’ve been tearing my hair out trying to figure out how to do this. I have a set of GameObjects with one script attached, which has a bool. I also have a controller which automatically adds each of the GameObjects with this script to it.

The behaviour I want is for if any number of these bools is set to true, some audio starts playing but currently if one or more is set to true, it’s being overridden by the others still being false. I’d like to know how to check each of the scripts from the values added to the list and check each of their bools individually and if just one is set to true, start the audio regardless of whether the others are false.

Thank you!

Grab all references of you components ( scripts ) into array or list, iterate trough it and check that bool for each, if found first true, DoSomething() and break the loop.
To get array of components you can use:

FindObjectsOfType<MyScript>();

or (if you know all componnets are in children of game object you have you controller script on)

GetComponentsInChildern<MyScript>();