using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlaySounds : MonoBehaviour { private AudioSource sound; public string soundName; private float isDestroyTimer; void Start() { // isLoopSound = false; sound = this.GetComponent(); PlaySound(); } void Update() { //isDestroyTimer -= Time.deltaTime; //if (isDestroyTimer <= 0) //{ // //Destroy(this.gameObject); //} } // Update is called once per frame public void PlaySound() { if (sound != null) { sound.clip = (AudioClip)Resources.Load(soundName, typeof(AudioClip));//调用Resources方法加载AudioClip资源 sound.Play(); // isDestroyTimer = sound.clip.length; } } }