How can I access a bool for a specific gameObject from the foreach loop?

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
	}
}

Your problem is that you’re not saving individual bools. Instead you just have a single bool which is in no way attached to a specific GameObject.

The best way to correct this would be to add a script to each GameObject. For now this could be as simple as…

public class MyNewClass
{
    public bool aBool;
}

Now in the script you’ve posted above you can do

private MyNewClass[] myNewClassArray;

void Update ()
{
    foreach (MyNewClass thisClass in myNewClassArray)
    {
       if (someCondidtion)
       {
         thisClass.aBool = true;
       }
       else
       {
         thisClass.aBool= false;
       }
    }
}

Now, each object has its own unique bool which is stored and can be referenced.

I solved the problem by storing the bool information in another script that is attached to each of the gameobjects in the array anyway. Thank you for all the answers!!!