FootstepEventsAnimation.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536
  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.Events
  5. {
  6. /// <summary>
  7. /// A variation of the base <see cref="FootstepEvents"/> which responds to Animation Events called "Footstep" by
  8. /// playing a sound randomly selected from an array, using the Int Parameter of the event as the index to determine
  9. /// which foot to play the sound on. 0 is the Left Foot and 1 is the Right Foot.
  10. /// </summary>
  11. /// <example><see href="https://kybernetik.com.au/animancer/docs/examples/events/footsteps">Footstep Events</see></example>
  12. /// https://kybernetik.com.au/animancer/api/Animancer.Examples.Events/FootstepEventsAnimation
  13. ///
  14. [AddComponentMenu(Strings.ExamplesMenuPrefix + "Footstep Events - Footstep Events Animation")]
  15. [HelpURL(Strings.DocsURLs.ExampleAPIDocumentation + nameof(Events) + "/" + nameof(FootstepEventsAnimation))]
  16. public sealed class FootstepEventsAnimation : MonoBehaviour
  17. {
  18. /************************************************************************************************************************/
  19. [SerializeField] private FootstepEvents _FootstepEvents;
  20. [SerializeField] private AudioSource[] _FootSources;
  21. /************************************************************************************************************************/
  22. // Called by Animation Events.
  23. private void Footstep(int foot)
  24. {
  25. _FootstepEvents.PlaySound(_FootSources[foot]);
  26. }
  27. /************************************************************************************************************************/
  28. }
  29. }