public void NextLevel()
{
// 播放音效
audioSource.Play();
// 獲取音效時間長度
float audioTime = audioSource.clip.length;
// 獲取當前場景編號
int index = SceneManager.GetActiveScene().buildIndex;
// 播放完音效後才載入下一個場景
StartCoroutine(DelayAndLoadScene(audioTime,
index + 1));
}
private IEnumerator DelayAndLoadScene(float time, int sceneIndex)
{
yield return new WaitForSeconds(time);
SceneManager.LoadScene(sceneIndex);
}
沒有留言:
張貼留言