Hello i have splash screen video about 12sec. which is playing on the first scene but I cant wait for it to finish and change to another scene. It just change scene straight away…
Code looks like this:
public VideoPlayer videoPlayer;
// Use this for initialization
void Start()
{
Screen.sleepTimeout = SleepTimeout.NeverSleep; // Screen never sleeps
StartCoroutine(PlayVideo());
}
IEnumerator PlayVideo()
{
//Play Video
videoPlayer.Play();
while (videoPlayer.isPlaying)
{
Debug.Log("Waiting for video to finish");
yield return null;
}
SceneManager.LoadScene(1);
//Debug.Log("Done Playing Video");
}
Thanks in advance.
Looks like there is a period of time to prepare the video to be played so at those frames its not considered as playing (returns false) , fortunately you can add the isPrepared condition:
IEnumerator PlayVideo()
{
//Play Video
videoPlayer.Play();
while (!videoPlayer.isPrepared || videoPlayer.isPlaying)
{
Debug.Log("Waiting for video to finish");
yield return 0;
}
SceneManager.LoadScene(1);
//Debug.Log("Done Playing Video");
}