我正在尝试统一制作过场动画,我需要在另一个音频剪辑通过后播放 2 秒的音频。我怎么能这样做?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ButtonActionHolder : MonoBehaviour
{
public AudioSource source;
public AudioClip drnefariotalk1;
public AudioClip childtalk;
public AudioSource AudioSource;
public AudioClip drnefariotalk2;
IEnumerator Timer()
{
yield return new WaitForSeconds(31f);
source.PlayOneShot(childtalk);
}
void Start()
{
StartCoroutine(Timer());
}
public void Play()
{
SceneManager.LoadScene(2);
}
}
什么意思过去了?它结束了吗?我认为一个可能的解决方案是:
IEnumerator Timer()
{
yield return new WaitForSeconds(31f);
source.PlayOneShot(childtalk);
yield return new WaitForSeconds(childtalk.length+2f);
source.PlayOneShot(drnefariotalk1)
}
如果前一个不起作用,请尝试此选项。基本上这在播放音频时停留在 while 循环中,当它停止时启动计时器,然后播放第二个音频片段:
source.PlayOneShot(audioclip1);
while(source.isPlaying()) {
yield return null
}
yield return new WaitForSeconds(2f);
source.PlayOneShot(audioclip2);