Adding experience + animation before destroy enemy.
Hi people, i need some help. I want an enemy give me experience when he die, but also i need the animation plays before the object is destroyed. This is the code i have:
if (curHp <= 0)
{
anim.SetBool ("Destroy", true);
Destroy (gameObject,0.1f);
thePlayerStats.AddExperience(expToGive * lvl);
}
The animation plays before the object is destroyed, but i recieve more experience than im supposed to recieve, Its because the collider of the monster keeps in collission with the game object i throw for take damage. I also trie this but doesnt work:
if (curHp <= 0)
{
Destroy (bxCollider);
anim.SetBool ("Destroy", true);
Destroy (gameObject,0.1f);
thePlayerStats.AddExperience(expToGive * lvl);
}
Thanks to all.
Thanks for the help but i cant figure out how to use it in this case. I tried, but the main problem at the time of the collision, this happens several times before the object is destroyed. So I get experience each time the collision occurs.
Your answer
![](https://koobas.hobune.stream/wayback/20220612095624im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Destroy Problem 2 Answers
How do I delete objects in an animation in a certain order? 1 Answer
Script isn't checking animator state 0 Answers
Simple call animation then destroy? 0 Answers
Destroying object after animation 2 Answers