I’m trying to use this coroutine to have my player a) freeze in place on death b) play the full death animation clip and c) load the level. If I put isKinematic before the yield, the animation doesn’t finish. If I put it after, the player continues falling after the animation is played. Any suggestions would be greatly appreciated!
private IEnumerator DeathAnim ()
{
deathSound.Play ();//plays the death sound
animation.Play("Death");//plays the death animation
yield return new WaitForSeconds(.3f);//give the animation time to finish
rigidbody2D.isKinematic = true;//freeze the rigidbody2D of the player
Application.LoadLevel (Application.loadedLevel);//reload the current level
}
You can use the length of the animation as the wait parameter to your yield statement.
private IEnumerator DeathAnim ()
{
deathSound.Play ();//plays the death sound
animation.Play("Death");//plays the death animation
yield return new WaitForSeconds(animation["Death"].length);//Use the length of the animation clip as the wait time for yield
rigidbody2D.isKinematic = true;//freeze the rigidbody2D of the player
Application.LoadLevel (Application.loadedLevel);//reload the current level
}
private IEnumerator DeathAnim ()
{
rigidbody2D.isKinematic = true;//freeze the rigidbody2D of the player
deathSound.Play ();//plays the death sound
animator.SetInteger ("AnimState", 1);
yield return new WaitForSeconds(1);//Use the length of the animation clip as the wait time for yield
Application.LoadLevel (Application.loadedLevel);//reload the current level
}