I want to do menu animation. In the animator, its contain 2 animations. One is opening animation, the other is closing animation. I set the opening animation as default state and added condition between of them. The condition contains one parameter, it is a bool type parameter. I drag the script which controls they behaviours on gameobject and animator component, but when the opening animation plays and player clicks the play button the parameter turns into true but it doesn't play.

 Animator canvasAnim;

 public Button lvlSelector;
 Button lvlSelector_A;

 // Use this for initialization
 void Start () {
     canvasAnim = GetComponent<Animator>();

     lvlSelector_A = lvlSelector.GetComponent<Button>();

 IEnumerator SlideLevelSelectMenu()

     yield return new WaitForSeconds(1f);

 void LevelSelector()
     canvasAnim.SetBool("clickedclose", true);


Gameobject that keeps script component


2 Answers 2


Maybe you should add your onClick method as an AnimationEvent after the MainMenuClosing animation finishes. Animation Events allow you to add data to an imported clip which determines when certain actions should occur in time with the animation.enter image description here

(Sorry couldn't post this as a comment)


Its a better idea not to use unity's animation system for UI animation. For the purpose of UI Animation use a Tween Library. I use DOTween for UI related animation. Its really easy to use as well.

For example if I had to make a simple scale animation on button click I can do something like this

void OnClick()

You can also add sequence of Animations for complex effects. This video from GameDevGuide explains it better: https://www.youtube.com/watch?v=Ll3yujn9GVQ

  • 1
    \$\begingroup\$ Is there a reason why you are saying it is not a good idea to use the unitys animation system for UI animation? \$\endgroup\$
    – Zibelas
    Aug 24, 2022 at 18:24
  • \$\begingroup\$ It implies some pretty bad performance on your game. Also using a tween is a lot easy and cleaner than using a complicated animator for a small animation. This video explains it better. youtu.be/Ll3yujn9GVQ \$\endgroup\$ Dec 4, 2022 at 19:11
  • \$\begingroup\$ I use Unity animation on my UI with no issues whatsoever. I'm not quite sure what you're talking about to be honest. \$\endgroup\$
    – Pow
    Feb 15 at 23:36
  • \$\begingroup\$ If you are a beginner, working on a small game and don't want to learn Tween, then don't bother. However, as you add more and more UI animation, you start hurting the performance of your game. Unity's Animator system relies on the Update loop to update animations, which can lead to additional calls to update UI elements. This can affect performance, especially if there are many UI elements being animated or if the animations are complex. Tweening, on the other hand, is simply an interpolation between two values over time, its lightweight, performant and easy to use for complex animations. \$\endgroup\$ Feb 16 at 1:47
  • \$\begingroup\$ That makes sense, but how do you think it interpolates between values? If you're claiming that Unity does it every frame then how does Tween do it? \$\endgroup\$
    – Pow
    Feb 16 at 10:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .