PlayOneSound.cs 691 B

12345678910111213141516171819202122232425262728
  1. // MIT License
  2. // https://gitlab.com/ilnprj
  3. // Copyright (c) 2020 ilnprj
  4. using UnityEngine;
  5. namespace RadarComponents
  6. {
  7. /// <summary>
  8. /// Play one sound. This component must be thrown into the PulseDistance script.
  9. /// </summary>
  10. [RequireComponent(typeof(AudioSource))]
  11. public class PlayOneSound : AbstractExtensionTarget
  12. {
  13. private AudioSource source;
  14. private void Awake()
  15. {
  16. source = GetComponent<AudioSource>();
  17. source.loop = false;
  18. }
  19. public override void UpdateExtensionView(Transform player, ITarget inputTarget)
  20. {
  21. source.PlayOneShot(source.clip, 1.0f);
  22. }
  23. }
  24. }