Search code examples
c#user-interfaceanimationunity-game-engineanimator

Unity Animator - Have an animation at the start and end of a scene


I'm new to Unity, and I'm struggling to create a simple animation with the animator. I want a GUI to have an animation at the beginning and end of a scene. The entry animation is "NextLevelGUI", and the exit is "FadeOut". I've attempted connecting the Any State block to these animations with conditions enabled by the scripts, but this does not work. Also, I hate to use an "Empty" animation, but I don't want there to be a animator-controlled entry animation. Would it be better just to script the animations?

Animator image

enter image description here


Solution

  • Using script you need to do:

    public class BrandBtn : MonoBehaviour
    {
        public Animator _anim;
    
        void Start()
        {
            _anim.Play("NextLevelGUI");
        }
    
        IEnumerator EndScene()
        {
            _anim.Play("FadeOut");
            yield return new WaitForSeconds(anim.GetCurrentAnimatorStateInfo(0).length+anim.GetCurrentAnimatorStateInfo(0).normalizedTime);
            // Load next scene
        }
    }