視頻播放完畢后,執行某個方法
方法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();
}