Detect multiple gamobjects

In my project I’m trying to use a large cube to detect multiple smaller cubes inside of the large cube so that I can run the smaller cubes through a foreach loop to separate them by characteristics, So now I’m wondering how I would go about storing those objects inorder to run them through the foreach loop.
If this isn’t clear enough I will elaborate,
Thanks for your time.

-Bazzalisk

@Bazzalisk,

I don’t think it’s necessary to parse the objects to categorize them, you can just do something like this in a script attached to the big trigger cube.
Here I assumed that you created the following class members:

private List<GameObject> list1 = new List<GameObject>();
private List<GameObject> list2 = new List<GameObject>();
private List<GameObject> list3 = new List<GameObject>();

And then in the script you add the two Unity handlers:

public void OnTriggerExit(Collider other)
{
    if (other.CompareTag("Some Tag"))
        list1.Add(other.gameObject);
    else if (other.CompareTag("Some other Tag"))
        list2.Add(other.gameObject);
    else if (other.CompareTag("Some more Tag"))
        list3.Add(other.gameObject);
}

public void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("Some Tag"))
        list1.Remove(other.gameObject);
    else if (other.CompareTag("Some other Tag"))
        list2.Remove(other.gameObject);
    else if (other.CompareTag("Some more Tag"))
        list3.Remove(other.gameObject);
}

Hope this helps :wink:

-Pino