Skip to content

Animation Extensions

Andrzej Kebab edited this page May 27, 2024 · 4 revisions

Animation Extensions

The Animation Extensions in this utility library provide a range of methods to enhance your animations in Unity. These extensions simplify the process of working with animations, making it easier to implement smooth, dynamic transitions in your projects.

Play Animation

public static void PlayAnimation(this Animator animator, string animationName)

Plays the specified animation on the given animator.

  • animator: The Animator component where the animation will be played.
  • animationName: The name of the animation to play.

Example

public class PlayExample : MonoBehaviour
{
    public Animator animator;

    void Start()
    {
        animator.PlayAnimation("Run");
    }
}

Stop Animation

public static void StopAnimation(this Animator animator, string animationName)

Stops the specified animation on the given animator.

  • animator: The Animator component where the animation will be stopped.
  • animationName: The name of the animation to stop.

Example

public class StopExample : MonoBehaviour
{
    public Animator animator;

    void StopRunning()
    {
        animator.StopAnimation("Run");
    }
}

Pause Animation

public static void PauseAnimation(this Animator animator)

Pauses all animations on the given animator.

  • animator: The Animator component where the animations will be paused.

Example

public class PauseExample : MonoBehaviour
{
    public Animator animator;

    void PauseAllAnimations()
    {
        animator.PauseAnimation();
    }
}

Resume Animation

public static void ResumeAnimation(this Animator animator)

Resumes all paused animations on the given animator.

  • animator: The Animator component where the animations will be resumed.

Example

public class ResumeExample : MonoBehaviour
{
    public Animator animator;

    void ResumeAllAnimations()
    {
        animator.ResumeAnimation();
    }
}

Is Playing

public static bool IsPlaying(this Animator animator, string animationName)

Checks if the specified animation is currently playing on the given animator.

  • animator: The Animator component where the animation status will be checked.
  • animationName: The name of the animation to check.

Example

public class IsPlayingExample : MonoBehaviour
{
    public Animator animator;

    void Update()
    {
        if (animator.IsPlaying("Jump"))
        {
            Debug.Log("Jump animation is playing.");
        }
    }
}

Clone this wiki locally