BasicMovementAnimations.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2022 Kybernetik //
  2. #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
  3. using UnityEngine;
  4. namespace Animancer.Examples.Basics
  5. {
  6. /// <summary>
  7. /// Plays a movement animation while the user holds W or Up Arrow.
  8. /// Otherwise plays an idle animation.
  9. /// </summary>
  10. /// <example><see href="https://kybernetik.com.au/animancer/docs/examples/basics/movement">Basic Movement</see></example>
  11. /// https://kybernetik.com.au/animancer/api/Animancer.Examples.Basics/BasicMovementAnimations
  12. ///
  13. [AddComponentMenu(Strings.ExamplesMenuPrefix + "Basics - Basic Movement Animations")]
  14. [HelpURL(Strings.DocsURLs.ExampleAPIDocumentation + nameof(Basics) + "/" + nameof(BasicMovementAnimations))]
  15. public sealed class BasicMovementAnimations : MonoBehaviour
  16. {
  17. /************************************************************************************************************************/
  18. [SerializeField] private AnimancerComponent _Animancer;
  19. [SerializeField] private AnimationClip _Idle;
  20. [SerializeField] private AnimationClip _Move;
  21. /************************************************************************************************************************/
  22. private void Update()
  23. {
  24. float forward = ExampleInput.WASD.y;
  25. if (forward > 0)
  26. {
  27. _Animancer.Play(_Move);
  28. }
  29. else
  30. {
  31. _Animancer.Play(_Idle);
  32. }
  33. }
  34. /************************************************************************************************************************/
  35. }
  36. }