LaboratoryProtection/Assets/UnityTest/ZXL/Scripts/Test/AutoCloseSelf.cs

71 lines
1.4 KiB
C#
Raw Normal View History

2023-10-05 02:31:29 +08:00
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<AudioSource>();
}
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,
,
,
_,
}
}