- Home /
Question by
mafiozooo · May 21, 2016 at 11:13 AM ·
animationanimatorscene loadrestart gameloaded
How to play animation on LoadedLevel
okay so I have animation that plays when I press button "play " also the game starts. when I die there is a restart button that uses this
public void RestartGame()
{
PlayerPrefs.SetInt("AutoPlay", 1);
Application.LoadLevel(Application.loadedLevel);
GetComponent<Animator>().SetBool("Slide", true);
}
but the animation just stays frozen ...
Comment
Answer by LLIV · May 22, 2016 at 12:26 AM
Loading the level resets stuff so the code that you wrote may not be run. Unless you're using DontDestroyOnLoad();
Your script is being reloaded along with everything else when you call a restart. This means that GetComponent<Animator>().SetBool("Slide", true);
isn't going to work in the same void as your restart. I strongly encourage you make a script that doesn't get reloaded on restart with DontDestroyOnLoad();
and set the animator's bool on that script instead after the level is finished loading.