Animation or programming?

Hi guys, Im making a 2d game, i want an animated UI (e.g. the start button sliding from the top), what will be more optimal, make this with animations or via Script?

you should use the animator in unity if it is dropping a button down into the center try looking at the ui transitions tutorial video to see how this is done

Animations for sure. Lerping through script is archaic in comparison, especially for things as automated and boring as ui.

GUI things can’t be animated unless you’re super experienced. And even then the control is minimal.

I suggest using 2d sprites, and then some touch logic based on what a raycast hits.

As far as animating 2D sprites: drag the sprite into a 2d field > add an animation component > open the animation window (ctrl + 6) > add a curve (transform position / scale / rotation / w/e) > key frame it > control it through script:


var animateUI : boolean;
  GetComponent(Animator).SetBool("AnimateUI", true);

(After adding an Animator component and creating a new clip in the animation tab, go into the Animator Tab and set up your bool (bottom left) and make appropriate transition links.)

of course make an instance of the component and bool for optimization reasons via script. It’s infinitely easier and more flexible than lerping values with mechanical results. Some scripting such as the example above would be necessary, but it will pale in comparison to animating without the Animator component.

edit - Even better:

var animateUI : boolean;
private var anim : Animator;

anim.SetBool("AnimateUI", animateUI);

   animateUI = true;