Editing Animations

To edit an animation, you will first need a reference to it. An animation is just the AnimationData class. UIAnimationData and TransformAnimationData both inherit from AnimationData and don't have any fundamental differences.

Any changes you make to the animation data will be reflected even while the animation is running.

All editable animation variables are public.

Pause or Play An Animation

Play

The AnimationData.Play method will set the isPaused value to false and will register the animation if it's not already registered.

animation.Play();

Pause

You can pause the animation in 2 ways:

animation.Pause();
animation.isPaused = true;

Both are identical.

Reverse

You can play an animation in reverse by setting the reverse value to true.

animation.reverse = true;

Finish

To finish an animation (reach its end state) immediately, use the AnimationData.Finish method.

animation.Finish();

Reset

There are 3 methods related to animation resetting.

1. Reset Time Method

animation.ResetTime();

This method will only reset time-related values of the animation.

2. Reset Method

animation.Reset();

This method will completely reset the animation; even the on-start events will be invoked again.

3. Start State Method

animation.StartState();

This works similarly to Reset. The only difference is that even if the animation is not playing, it will force the animation to run the first frame of the animation once.

Animation Curve

You can even change the animation curve while the animation is running.

animation.animationCurve = Ease.OutInQuart;

Last updated