I have following code in my take damage function
if (isAlive)
{
towerHealth -= damageAmount;
if (towerHealth <= 0)
{
isAlive = false;
anim.Stop();
}
}
This works properly most of the time.
But once in a while I get following error, NullReferenceException: Object reference not set to an instance of an object
I trace the error to anim (tk2dSpriteAnimator) becoming null.
The main game object with the sprite is active, any idea how this could happen?
Any advice on how to fix this?