How do i check if all tagged objects are inactive?

I have multiple objects that are active and when shot they deactivate.

How can i check when all of them are deactivated and then play audio?

Here is what i have tried…

function Update () {
    for(var fooObj : GameObject in GameObject.FindGameObjectsWithTag("Cubetarget"))
    {

  
    if(fooObj.active == false)
    {
    	audio.Play();
    	print("cubetargets are no longer active");
    
    }
    print("cubetargets are still active");
    }
}

This script is attached to the parent of all the targets as they are all grouped.
It only says “Cubetargets are still active”

Could anyone tell me where I am going wrong?

Thanks

Give this a go:

function Update () {
	var targets: GameObject[] = GameObject.FindGameObjectsWithTag("Cubetarget"); // Get the array of gameobjects
	var areAnyTargetsActive : Boolean = false; // Make an assumption, no active targets

	for (var i : int = 0; i < targets.Length; i++ ) {
		if (targets*.active == true) {*
  •  	areAnyTargetsActive = true;*
    
  •  	break; // break out of the for loop early since continuing would waste time*
    
  •  }* 
    
  • }*

  • if (areAnyTargetsActive == true) {*

  •  print("cubetargets are still active");*
    
  • } else {*

  •  print("cubetargets are no longer active");*
    
  • }*
    }

FindGameObjectsWithTag only returns active objects.

GameObject [] objs = GameObject.FindGameObjectsWithTag("Cubetarget");
if(objs.Length == 0)
{
    // No active items
}