PlaySounds.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PlaySounds : MonoBehaviour
  5. {
  6. private AudioSource sound;
  7. public string soundName;
  8. private float isDestroyTimer;
  9. void Start()
  10. {
  11. // isLoopSound = false;
  12. sound = this.GetComponent<AudioSource>();
  13. PlaySound();
  14. }
  15. void Update()
  16. {
  17. //isDestroyTimer -= Time.deltaTime;
  18. //if (isDestroyTimer <= 0)
  19. //{
  20. // //Destroy(this.gameObject);
  21. //}
  22. }
  23. // Update is called once per frame
  24. public void PlaySound()
  25. {
  26. if (sound != null)
  27. {
  28. StartCoroutine(LoadDll2.DownLoadAssets((AssetBundle ab) =>
  29. {
  30. AudioClip obj = ab.LoadAsset<AudioClip>("SCAudiosConfig");
  31. sound.clip = obj; // (AudioClip)Resources.Load(soundName, typeof(AudioClip));//调用Resources方法加载AudioClip资源
  32. sound.Play();
  33. }));
  34. // isDestroyTimer = sound.clip.length;
  35. }
  36. }
  37. }