- Home /
Wait for Animation
I know this question has been asked many times, but none of them worked for me. I want it to wait for the death animation before it exits the level. Thanks.
if (health == 0)
{
anim.Play("Death", 0);
for (int i = 0; i < 1; i++)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}
Answer by davidcox70 · May 04, 2018 at 03:41 PM
You might want to look into animation events as the best way. But a quick solution if you know how long your "death" animation lasts is to simply delay calling your load scene;
anim.Play("Death",0);
Invoke("nextLevel",2); // wait two seconds
void nextLevel(){
SceneManager..... // load your scene
}
@davidcox70 Thanks for the help, but that still didn't work.
@AutisticWiz , $$anonymous$$'s solution should work. Would you $$anonymous$$d explaining how is it now working? What's happening and how is that different from what you're expecting to happen? Furthermore, showing exactly the code you used to test his method would help a lot to deter$$anonymous$$e the problem.
As a side note. That for loop in your code is redundant. It will run only once, so the result would be exactly the same if you got rid of it and only left the LoadScene method.