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”
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*