Hi!
I have a foreach loop that sets a bool to true or false for each object in an array. I now want to use this bool for another function but the problem is that it’s only set for the GameObjects that accomplish the conditions given in the foreach loop. Therefore if I log it, the bool is always set to false. How can I access a bool for a specific gameObject from the foreach loop? Does something like gameObject1.GetComponent(aBool) work? Or how can I set the bool true for the whole script, so it will log it as true? Thanks!
private GameObject[] gameObjects;
private bool aBool;
void Update ()
{
foreach (GameObject gameObject in gameObjects)
{
if (someCondidtion)
{
aBool = true;
}
else
{
aBool = false;
}
}
}
void OnTriggerEnter ()
{
if (aBool)
{
// do something
}
}