Hi all,
I only have basic ability with Unity and cannot figure out the answer to what looks like a simple question. I have three enemies in my level, and would like to spawn a ‘boss’ once they’re defeated. Here is my code so far:
public static var enemyCount : int = 3;
public static var bossHealth: int=3;
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)
{
var instance : GameObject = Instantiate(Resources.Load("boss"));
if(collision.gameObject.tag == "fireball")
{
animation.Play("dying");
audio.Play();
bossHealth -= 1;
if(bossHealth<=0)
{
yield WaitForSeconds(0.2);
GameObject.Destroy ( gameObject ) ;
Application.LoadLevel ("Level_1_a_Clear");
}
}
}
}
This script is attached to every enemy in the game. In fact, at the moment, all enemies are the same (loaded from a prefab). Currently, what happens is that when I defeat all three enemies, my boss spawns. Great! Problem is, he cannot be killed. I can shoot infinite fireballs at him and he plays his ‘hit’ animation and audio clip but continues to live! Do any of you see where I’m going wrong here?
Your help is much appreciated.
Many thanks!