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();
    }
posted @ 2020-01-10 18:06  Aaron丶Han  阅读(7666)  评论(0编辑  收藏  举报