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.

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 :slight_smile:

You can use Animation Events too, just put it on the last frame of your animation with a method attached to it.

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.