Activating a 'boss' in the scene once all enemies are destroyed

Hi all,

I’ve been doing A LOT of reading as to how I can get my ‘boss’ to appear once all the mini enemies are destroyed. Initially, I successfully achieved this via instantiation, but then could not get my instantiated boss to follow waypoints like my other enemies (you can see my initial question here in case you have an answer for it).

Having tried a lot of methods to accomplish this (and failing), I’ve decided to change the way this works and use SetActive() to make my boss appear instead of instantiating him. Using this will enable me to assign waypoints to him a lot easier. I’ve been doing a lot of research on this and have tried several solutions, but encountering the following problem. I am able to deactivate my boss on startup, but cannot activate him once all enemies are destroyed.

Here is my EnemyDead.js script (which is attached to all four enemies in the scene):

public static var enemyCount : int = 4;
GameObject.Find("boss").SetActive(false);

function OnCollisionEnter( collision : Collision ) 

 {

      if(collision.gameObject.tag == "fireball")

      {
      animation.Play("dying");
      audio.Play();
 yield WaitForSeconds(0.2);
         GameObject.Destroy ( gameObject ) ;

         enemyCount -= 1;
}
if(enemyCount <= 0) {

GameObject.Find("boss").SetActive(true);

  }}

We can see here that if all enemies are destroyed, the boss should load. However, he does not. I’ve read that you cannot use GameObject.Find(“string”) to activate an object that’s been deactivated, but cannot find an alternate route around this.

I’ve tried .active, SetActiveRecursively, activeSelf, activeInHierarchy - the lot. For your information, I am using Unity 4. Any support or guidance would be much appreciated. Apologies if this is such a simple question, I can’t get my head around it!

Many thanks for your time in advance!

Basically if the object is not enabled then the find function wont find it (Which I have found very annoying). You can create some other way to disable it such as a local variable like “isAlive” or something, therefore never setting it to disabled or you could store a pointer to a boss enitiy before turning the entity off. The problem isn’t activating a disabled entity. The problem is using the find function to get access to it.