Hello
I have a problem. When my enemy dies, it plays an animation and after it is finished the enemy will be destroyed.
The problem is when my enemy is playing the animation and I shoot a bullet, it is still adding a score.
How can I fix it to stop shooting at my “dying” enemy and only add a score once.
You have to excuse me for my english =/
Thanks
My code :
public void OnTriggerEnter2D(Collider2D col) {;
if(col) {
Health -= 1;
Destroy(col.gameObject);
if(Health <= 0) {
enemy_anim.SetBool("dying", true);
isAlive = false;
StartCoroutine(Die());
ScoreManager score = levelManage.GetComponent<ScoreManager>();
score.Score += 10;
}
}
}
private IEnumerator Die() {
AnimatorStateInfo info = enemy_anim.GetCurrentAnimatorStateInfo(0);
yield return new WaitForSeconds(info.length + 1f);
Destroy(gameObject);
}