Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

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

$
0
0
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**][1] 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! [1]: http://answers.unity3d.com/questions/696025/assigning-waypoints-to-an-instantiated-enemy.html

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>