banner



How To Check If Animation Ended Unity

Nosotros all know that adding a few animations makes a game x times improve!
Only what if you are a programmer and all yous can practise is to write code? Yous can animate from code!

Principles of Animation

One of the things that you need to sympathise before you brainstorm to brand animations is to start with 12 principles of animation. Those were introduced in the book: "The Illusion of Life: Disney Animation".
This is a great place to start considering it gives you some thought about how to make animations in full general. At this point, there is a lot of videos that feature this subject and my favorite ane is by AlanBeckerTutorials and I would highly recommend watching it first. 🤓

Earlier we starting time coding

And then to begin with our coding role let me explain how it's going to piece of work.
Each blitheness that I'm going to create will exist fastened to the object as a component. Based on our employ case animation can exist removed later on some time or information technology tin loop infinitely. As an addition, I'thousand going to use Mathfx script available on Unify Wiki to accept an option to change a fashion in which element will be blithe.

Implementation

To implement our animation we are going to exercise it in 2 parts.
First, we will need to have a base form that will handle the blitheness itself.

using UnityEngine; using UnityEngine.Events;  /// <summary> /// Base animation class. /// Override methods in Blitheness Controls region to create new animation. /// </summary> public class BaseAnimation : MonoBehaviour {     // Types of bachelor animation curves     public enum AnimationCurveEnum     {         Hermite,         Sinerp,         Coserp,         Berp,         Bounce,         Lerp,         Clerp     }      [Header("Blitheness Settings")]     // Animation duration     public float duration = 1f;     // Animation delay     public float delay = 0f;     // Is blitheness looping     public bool isLooping = false;      // Should animation start playing on enable     public bool autoPlay = false;     // Should animation destroy itself after finish of blitheness     public bool autoDestroy = true;      // Animation bend     public AnimationCurveEnum animationCurve = AnimationCurveEnum.Hermite;      // On finish event     public UnityAction OnAnimationFinished;      // Is animation playing     protected bool isPlaying = simulated;      // Internal blitheness timer     protected bladder timer = 0f;      #region [Blitheness Controls]      /// <summary>     /// Method called to start animating with this component.     /// When overriding, y'all tin treat it as Start or Awake function.     /// </summary>     public virtual void StartAnimation()     {         isPlaying = truthful;     }      /// <summary>     /// Internal blitheness loop.     /// You lot can override this function merely I would recomment to override UpdateAnimation(float t).     /// </summary>     protected virtual void UpdateAnimation()     {         UpdateAnimation((timer - delay) / (duration));     }      /// <summary>     /// Internal animation loop.     /// You can override information technology and add your animation lawmaking. Comes with parameter "t" which has value from 0.0 to i.0.     /// </summary>     /// <param name="t">t receives values from 0.0 to 1.0.</param>     protected virtual void UpdateAnimation(float t)     {         // Hither goes code for animation with t (0.0 -> 1.0)     }      /// <summary>     /// Method used to intermission animation.     /// </summary>     public virtual void PauseAnimation()     {         isPlaying = false;     }      /// <summary>     /// Method used to stop animation.     /// </summary>     public virtual void StopAnimation()     {         PauseAnimation();         timer = 0;     }      /// <summary>     /// Method called on animation finished.     /// </summary>     protected virtual void FinishAnimation()     {         OnAnimationFinished?.Invoke();         StopAnimation();          if (autoDestroy)         {             Destroy(this);         }     }      

0 Response to "How To Check If Animation Ended Unity"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel