BasicMovementAnimations.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
  3. using UnityEngine;
  4. namespace Animancer.Samples.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. ///
  11. /// <remarks>
  12. /// <strong>Sample:</strong>
  13. /// <see href="https://kybernetik.com.au/animancer/docs/samples/basics/movement">
  14. /// Basic Movement</see>
  15. /// </remarks>
  16. ///
  17. /// https://kybernetik.com.au/animancer/api/Animancer.Samples.Basics/BasicMovementAnimations
  18. ///
  19. [AddComponentMenu(Strings.SamplesMenuPrefix + "Basics - Basic Movement Animations")]
  20. [AnimancerHelpUrl(typeof(BasicMovementAnimations))]
  21. public class BasicMovementAnimations : MonoBehaviour
  22. {
  23. /************************************************************************************************************************/
  24. [SerializeField] private AnimancerComponent _Animancer;
  25. [SerializeField] private AnimationClip _Idle;
  26. [SerializeField] private AnimationClip _Move;
  27. /************************************************************************************************************************/
  28. protected virtual void Update()
  29. {
  30. float forward = SampleInput.WASD.y;
  31. if (forward > 0)
  32. {
  33. _Animancer.Play(_Move);
  34. }
  35. else
  36. {
  37. _Animancer.Play(_Idle);
  38. }
  39. }
  40. /************************************************************************************************************************/
  41. }
  42. }