Hi all,
I am having the problem that between the time my player’s health reaches zero and the death animation finishes, if the player collides with another enemy, the player will continue to lose lives. Here is my code if anyone has any suggestions. I tried a coroutine with yield WaitForSeconds in the HealthScript, but that didn’t seem to help:
HealthScript:
public void Damage(int damageCount)//Inflicts damage
{
hp -= damageCount;
if (hp <= 0 && this.gameObject.tag == "Player") {
MainScript playerLives = this.GetComponent<MainScript> ();
playerLives.UpdateLives (1); //player lives minus one
}
}
MainScript:
public void UpdateLives(int livesLost){
playerLives -= livesLost;
HealthScript playerHealth = this.GetComponent<HealthScript> (); //get player health script
if (playerLives > 0){
StartCoroutine ("DieAnim");
}
private IEnumerator DieAnim ()
{
animator.SetInteger ("AnimState", 1);
yield return new WaitForSeconds(1);//death animation plays
Application.LoadLevel (Application.loadedLevel);//reload the current level
}