Ensuring that a movie's prepared before playing it with the prepareCompleted event

In the preceding recipe, the movie has time to prepare since the game waits until we press the jumo/space key. If we are using scripting to set up a Video Player for a video clip, we need to do some initial work before the video is ready to play. Unity provides the prepareCompleted event, which allows us to register a method to be invoked once a VideoPlayer is ready to play.

Do the following:

  1. Add a UI Raw Image to the scene by choosing menu: Create | UI | Raw Image.
  2. Create a new empty GameObject named video-object.
  3. Create a C# script class named PrepareCompleted, and attach an instance object as a component to GameObject's video-object:
 using UnityEngine; ...

Get Unity 2018 Cookbook - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.