using System; using System.Collections; using UnityEngine; namespace UnityTest.ZXL { [RequireComponent(typeof(AudioSource))] public class AutoCloseSelf : MonoBehaviour { [SerializeField] private AutoCloseSelfType _autoCloseSelfType; private AudioSource _audioSource; private void Awake() { _audioSource = GetComponent(); } private void OnEnable() { StartCoroutine(WaitClose()); } IEnumerator WaitClose() { yield return new WaitForSeconds(0.1f); _audioSource.Play(); Debug.Log("播放开始"); while (_audioSource.isPlaying) { yield return new WaitForFixedUpdate(); } Debug.Log("播放结束"); gameObject.SetActive(false); } } public enum AutoCloseSelfType { None, _1_1_1_气瓶泄露音效, _1_1_2_气瓶爆炸声, _1_2_1, _1_2_2, _1_3_1, _1_3_2, _1_3_3, _2_1_1, _2_1_2, _2_1_3, _2_1_4, _2_2_1, _2_2_2, _2_2_3, _2_2_4, _2_3_1, _2_3_2, _2_3_3, _2_3_4, _2_4_1, _2_4_2, _2_4_3, _2_4_4, _3_3, _119报警声, 气瓶火烧声, 微型爆炸, 消防栓_水枪声, } }