Hello
I have three targets in a scene made of cubes, called target1, target2, and target3. They are destroyed on collision with a RigidBody.
How do I know when these three objects are gone so I can call my ‘Game Over’ state?. They aren’t prefabs or dragged onto anything in the inspector right now, and their only component is the code to destroy themselves on collision.
Thanks in advance.
*** UPDATE ***
Thanks to Screenhog’s answer below, I was able to stop my counter counting up when all the targets are destroyed. Here’s the final code for reference.
private var timeElapsed:float = 0f;
var targets:Target[];
function Update(){
if (targets.length > 0){
timeElapsed += Time.deltaTime;
}
else {
print("Clock has stopped");
}
targets = FindObjectsOfType(Target) as Target[];
print("Target length is " +targets.length);
}
This trick of using a unique component to identify a group of objects and then using FindObjectsOfType is another really nice piece of the Unity puzzle slotting into place.
Thanks for the help.