Unity 音樂或者視頻播放完畢之后執行方法


視頻播放完畢后,執行某個方法

方法1

官方給的解釋

    private VideoPlayer video2;
    private void Awake()
    {
        video2.loopPointReached += test; //設置委托
    }
    void test(VideoPlayer video)//video = video2
    {
        Debug.Log("播放完畢");
    }

方法2

官方解釋

    private IEnumerator VideoCallBack(VideoPlayer VideoObject, Action action)//方法可以傳遞參數
    {
        Debug.Log(VideoObject.isPlaying);
        while (VideoObject.isPlaying)
        {
             yield return new WaitForFixedUpdate(); //跟FixedUpdate 一樣根據固定幀 更新
        }
        action();
    }

音頻同樣的道理 音頻我在文檔中沒有找到播放結束的委托

    private IEnumerator AudioCallBack(AudioSource AudioObject,Action action)
    {
        Debug.Log(AudioObject.isPlaying);
        while (AudioObject.isPlaying)
        {
            yield return new WaitForSecondsRealtime(0.1f);//延遲零點一秒執行
        }
        action();
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM