Q:

Detect if any object with tag is inside of trigger

I have an empty object with box collider (trigger), inside this empty object I have some cubes that have the same tag, so I want to instantiate a Text when all of those cubes becomes outside of the empty object (using OnTriggerExit).
This is the code I tried but it didn't work:
List<string> contacts = new List<string>();

void OnCollisionExit(Collision col)
{
    contacts.Add(col.gameObject.tag);
    if (contacts.Contains("Cube"))
    {
        GameObject canvas = GameObject.Find("Canvas");
        Text text = Instantiate(Text, new Vector3(562, 1800, 0), Quaternion.identity);
        text.transform.SetParent(canvas.transform);
    }
}

A:

Keep track of how many cubes are in the trigger. Set it at the scene start, increment using OnTriggerEnter and decrement using OnTriggerExit when the tag is "Cube". As soon as it hits zero, call your function.
// Inside of MonoBehavior on the GameObject with the trigger.
public int cubesCurrentlyInTrigger;

void Start() 
{
    cubesCurrentlyInTrigger = 3; // Or however many cubes at start
}

void OnTriggerEnter(Collider col) 
{
    // check for entering cubes
    if (col.tag == "Cube")
    {
        cubesCurrentlyInTrigger++;
    }
}

void OnTriggerExit(Collider col) 
{
    // check for exiting cubes
    if (col.tag == "Cube") 
    {
        cubesCurrentlyInTrigger--; // Could use `--cubesInTrigger` inside the if,
                                   // but this is more readable

        if (cubesCurrentlyInTrigger == 0) 
        {
            DoFunction(); // Put your function here.
        }
    }
}

