- Home /
scene loads faster than button animation
Hello I have animation added on button and on click event .On click new scene is entered but animation not even shown.How to finish animation before scene load? Just to let you know i m beginner at this.
Answer by Prastiwar · Dec 17, 2017 at 04:42 PM
Just make delay between starting animation and starting loading scene. You can do this by coroutine or Invoke method.
public void animScene()
{
anim.Play();
Invoke("LoadScene", delay);
}
void LoadScene()
{
SceneManager.LoadScene(Scene);
}`
Or with coroutine
public void animScene()
{
StartCoroutine(loadCoroutine());
}
IEnumerator loadCoroutine()
{
anim.Play();
yield return new WaitForSeconds(animTime);
SceneManager.LoadScene(Scene);
}
I tried this but its not working,i added on button click anim Scene ,there are no errors.Also I first tried public Animation anim,but it wont allow drag and drop in inspector even tought there is list
public class Level$$anonymous$$anager : $$anonymous$$onoBehaviour {
private Animation anim;
void Start()
{
GameObject.FindObjectOfType<Animation>();
}
public void AnimScene()
{
Invoke("LoadScene",5);
}
public void LoadScene(string selection)
{
Scene$$anonymous$$anager.LoadScene(selection);
}
}
So, you have different problem that I've thought.
You just don't play your animation in this code. In Unity's $$anonymous$$ecanim system you need Animator component(and reference to this component in script) and animation in this animator controller and maybe Trigger, which you can set in script by anim.SetTrigger("NameOfTrigger");
For more information and visualize I would recommend learn section for animations: https://unity3d.com/learn/tutorials/s/animation