EffectSoundShoot.cs 491 B

123456789101112131415161718192021222324
  1. using UnityEngine;
  2. using System.Collections;
  3. public class EffectSoundShoot : MonoBehaviour {
  4. private AudioSource audioSource;
  5. private float startTime;
  6. public float duration = float.MaxValue;
  7. void Start()
  8. {
  9. audioSource = GetComponent<AudioSource>();
  10. startTime = GameTime.time;
  11. }
  12. // Update is called once per frame
  13. void FixedUpdate ()
  14. {
  15. if(audioSource == null || !audioSource.isPlaying || GameTime.time - startTime >= duration)
  16. {
  17. Destroy(this.gameObject);
  18. }
  19. }
  20. }