2019年6月16日 星期日

Unity 學習筆記 - 等待一段時間後才載入場景

直接上程式碼


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);
    }

沒有留言:

張貼留言

[Android][App] Pin Poke Challenge 隱私權保護政策

非常歡迎您使用「 Pin Poke Challenge 」,為了讓您能夠安心使用此 App 的各項服務與資訊,特此向您說明 Pin Poke Challenge的隱私權保護政策,以保障您的權益,請您詳閱下列內容: 一、隱私權保護政策的適用範圍 隱私權保護政策內容,包括...