An easier way to perform 2D sprite animations in Unity. By simply adding the EZAnimator component to the object you wish to animate, you can now easily play a list of sprites with a single method call.
Add this package via Unity's Package Manager using the Git URL: https://github.com/Svaerth/EZAnimator.git You can find more detailed instructions here
- Add the EZAnimator component to the object you wish to animate
- Procure a list of Sprite objects that you wish to make up the animation
- Use one of the overloads for the
Play()
orPlayCoroutine()
methods.
Example:
List<Sprite> RunningAnimation = new List<Sprite>(){
RunningSprite1, RunningSprite2, RunningSprite3
};
GetComponent<EZAnimator>().Play(RunningAnimation, 300);
Methods with the suffix 'Coroutine' are Coroutines, you can use these if you wish to pause a coroutine until an animation is done playing.
Example:
IEnumerator ChargeAndShoot()
{
var animator = GetComponent<EZAnimator>()
yield return StartCoroutine(animator.PlayCouroutine(ChargingAnimation, 300));
CreateFireball();
yield return StartCoroutine(animator.PlayCouroutine(RecoilAnimation, 300));
}
You can customize how the animation plays by populating the following optional parameters in the Play()
method:
- durationMilliseconds - how long (in milliseconds) it will take to play the whole animation.
- framesPerSecond - the speed of the animation measured in frames per seconds
- looping - whether or not the animation should loop
- reversed - whether or not the animation should play in reverse
- startingFrame - the frame of animation that the animation begin playing on
- endingFrame - the frame that the animation should stop playing on
NOTE: you must populate either durationMilliseconds or framesPerSecond but not both
You can stop the currently playing animation at any time by calling the StopCurrentAnimation()
method. You can also interrupt an animation with a new one by calling Play()
while an animation is already in progress.
You can cause the currently playing animation to go back to play in reverse starting with the frame it's currently on by calling ReverseCurrentAnimation()
. This might be useful if a player character is changing positions (like from standing to crouching) and before the transition animation is complete, the player decides to change to the previous position.