-
Notifications
You must be signed in to change notification settings - Fork 0
Animation Extensions
Andrzej Kebab edited this page May 27, 2024
·
4 revisions
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.
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.
public class PlayExample : MonoBehaviour
{
public Animator animator;
void Start()
{
animator.PlayAnimation("Run");
}
}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.
public class StopExample : MonoBehaviour
{
public Animator animator;
void StopRunning()
{
animator.StopAnimation("Run");
}
}public static void PauseAnimation(this Animator animator)Pauses all animations on the given animator.
-
animator: The Animator component where the animations will be paused.
public class PauseExample : MonoBehaviour
{
public Animator animator;
void PauseAllAnimations()
{
animator.PauseAnimation();
}
}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.
public class ResumeExample : MonoBehaviour
{
public Animator animator;
void ResumeAllAnimations()
{
animator.ResumeAnimation();
}
}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.
public class IsPlayingExample : MonoBehaviour
{
public Animator animator;
void Update()
{
if (animator.IsPlaying("Jump"))
{
Debug.Log("Jump animation is playing.");
}
}
}