So I have 2 different projectiles hitting an enemy.
1 gets reused and just goes off screen in an array, while the other destroys itself on contact.
Both call a function on the enemy to “flash hit” (flashes the enemies color to red to show it’s been hit)
However, the one that destroys itself, the enemy only starts the “flash” and doesn’t go back to normal.
If i put a delay before the destruction of the projectile, then it fully plays out the flash. So my question is, why does it matter? Should FlashHit () run independantly of the object that called it? Why doesn’t it just run on it’s own until completion?
The flash function for the enemy;
function FlashHit ()
{
var startTime : float = Time.time;
while (Time.time < startTime + hitFlash)
{
myAnimation.SetMeshColor(Color.Lerp (hitColor, normalColor, (Time.time - startTime)/hitFlash));
yield;
}
}