40 lines
864 B
C#
40 lines
864 B
C#
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace UnityTest.ZXL
|
|
{
|
|
public class Speak : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI speakContent;
|
|
|
|
private AudioSource _audioSource;
|
|
|
|
private void Awake()
|
|
{
|
|
_audioSource = GetComponent<AudioSource>();
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (_audioSource.clip != null)
|
|
{
|
|
StartCoroutine(PlayAudio());
|
|
}
|
|
}
|
|
|
|
IEnumerator PlayAudio()
|
|
{
|
|
var length = _audioSource.clip.length;
|
|
yield return new WaitForSeconds(length);
|
|
_audioSource.clip = null;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
StopAllCoroutines();
|
|
_audioSource.clip = null;
|
|
}
|
|
}
|
|
} |