In the last recipe of this chapter, we'll learn how a video can be displayed in the game scene. It is a useful feature—very handy for computer graphics scenes or cut scenes or if you want to include a monitor displaying a video clip in your game scene.
You need two things for this recipe. Firstly, install QuickTime on your PC, if you don't have it already. Without QuickTime, Unity cannot import video clips properly. The QuickTime installer can be downloaded from http://www.apple.com/quicktime/download/.
Next, we need a video clip. If you don't have a clip to use, you can load the video clip we have provided with the content of this book.
Videos
.Start()
function of the script:void Start () { MovieTexture mt = (MovieTexture)renderer.material.mainTexture; mt.Play(); }
Video clips are added to game objects in the scene as you would do with any other material. The difference is that, with video clips, the material is obtained from a video clip, instead of a texture.
That said, a very important aspect when dealing with videos is to correctly code them. On one side, you need quality, and on the other side, you need to keep the file as small as possible. Take into consideration the fact that importing long videos in Unity can take several minutes, and that whenever you change settings in the Inspector window, the clip is reimported and processed. This means you may find yourself waiting and waiting for the processing to be done, before being able to getting back to work!
With Unity, it is pretty easy to add videos and create the controls to pause, play, or stop the video. We recommend referring to the manual at http://docs.unity3d.com/Manual/class-MovieTexture.html to delve more into this matter.
3.137.217.17