I am new to programming, trying to do an intro (video) in the game and after the end of this video a certain action should take place (namely, a transition to another scene). I tried to do it using the number of frames in the video, but it didn't work out. Used VideoPlayer. In the official documentation I did not find similar functionality. Help me please(

failed attempt code

public void AutoLoadOurMenu() { ulong numberFramesInVideo; //количество кадров в видео numberFramesInVideo = videoPlayer.frameCount; ulong numberOfCurrentFrame; //номер текущего кадра numberOfCurrentFrame = (ulong) videoPlayer.frame; if (numberOfCurrentFrame== numberFramesInVideo) //ещё не совсем поняла, с 0 //или 1 идет отсчет кадров, но так: if (numberOfCurrentFrame== // numberFramesInVideo-1) тоже пробовала, тоже неудачно { Application.LoadLevel(1); } } 

    1 answer 1

    VideoPlayer contains the loopPointReached event, which is triggered when the VideoPlayer reaches the end of the video. In order for it to work, looping ( loop ) must be enabled in VideoPlayer. To call a function at the end of the video, you need to subscribe this function to this event:

     void OnEnable() //Сначала подписываем нашу функцию на событие конца видео { videoPlayer.loopPointReached += OnVideoEnd; } void OnDisable() //Отписываем для предотвращения утечки памяти { videoPlayer.loopPointReached -= OnVideoEnd; } void OnVideoEnd(UnityEngine.Video.VideoPlayer causedVideoPlayer) { //Нужный вам код, который будет выполняться, когда видео закончится } 

    Links: https://forum.unity.com/threads/how-to-know-video-player-is-finished-playing-video.483935/ https://docs.unity3d.com/ScriptReference/Video.VideoPlayer. html https://docs.unity3d.com/ScriptReference/Video.VideoPlayer-loopPointReached.html