Hello all! I’ve been trying to work on an enemy respawner and it just doesn’t seem to be working. I’ve tried a million different methods but scaling the object to nothing, changing the health of the object, then rescaling a few seconds later seems to work best, however, I can’t seem to figure out a way to get the enemy to respawn (after dying) an indefinite number of times without crashing unity.
The ApplyDamage function is referenced in another script and all it does is take away a certain amount of damage from the object. Currently when I hit the object, its damage decreases, but it keeps decreasing and never actually performs the Dead function and I am really not understanding why. Any help is appreciated. Thanks!
The code is as follows:
#pragma strict
var StartingHealth = 100;
var Health = StartingHealth;
var ActiveEnemy = true;
while (ActiveEnemy == true) yield;
{
if (Health < 0)
{
Dead();
}
}
function ApplyDamage (TheDamage : int)
{
Health -= TheDamage;
}
function Dead ()
{
gameObject.transform.localScale -= Vector3(1,1,1);
Health = StartingHealth;
Debug.Log("Before");
yield new WaitForSeconds(5);
gameObject.transform.localScale += Vector3(1,1,1);
Debug.Log("After");
}