- Home /
How to play Animation of a button first, THEN only proceeding to the next scene ?
Because when i click the button, the animation won't play, because Unity change scene too fast.
Answer by swanne · Nov 03, 2020 at 03:45 PM
Hey,
Use a coroutine to handle that. The coroutine can be called like any other function and then told to wait until you've done what you want before progressing with the rest of the code.
Look them up on the Unity Docs :)
public void InsertScene(string scene) { Scene$$anonymous$$anager.LoadScene(scene);
}
Bro, can you help edit this code, to have 1 second delay please..
In your function call
StartCoroutine(InsertScene(sceneName));
Then replace the public void function for this.
IEnumerator InsertScene(string _scene)
{
//Play the animation
//anim.Play("xxx");
//Wait for 1 Second
yield return new WaitForSeconds(1);
//After we have waited change the scene
Scene$$anonymous$$anager.LoadScene(scene);
}
Answer by Lucas_Lima_14 · Nov 05, 2020 at 07:59 PM
You can use Animation Events too, just put it on the last frame of your animation with a method attached to it.
Answer by Frostoise · Nov 10, 2020 at 11:07 PM
swanne has the correct answer but it has a flaw. If you use;
SceneManager.LoadScene(0);
your game might have a sharp lag, while the button animation finishes. Instead use ;
var async = SceneManager.LoadSceneAsync(0);
async.allowSceneActivation = false;
yield return new WaitForSeconds(2f);
async.allowSceneActivation = true;
This allows the game to load the scene in the background while your animation plays.
Your answer
Follow this Question
Related Questions
How to achieve a scene change transition like this 0 Answers
Old scene still appears for short time when switching scene 0 Answers
What is happening to scene manager.loadscene??? 2 Answers
It is possible to make live transition between scenes? 1 Answer
Is there any ideas to load Unity scene asynchronously? 1 Answer