Using scripting to control video playback on scene textures
While the previous recipe demonstrated how we can place videos using the VideoPlayer
component, which is set up at design time, much more is possible when controlling video playback through scripting – for example, allowing the user to interactively pause/play/stop video playback:
Figure 14.3: Example of using a script to control the video
In this recipe, we’ll use scripting to play/pause the playback of a video rendered onto a 3D cube.
Getting ready
If you need a video file to follow this recipe, please use the 54321TestVideo.mov
file included in the 14_02
folder.
How to do it...
To use scripting to control video playback, follow these steps:
- Create a new Unity 3D project.
- Import the provided
54321TestVideo.mov
file. - Create a 3D cube by going to GameObject | 3D Object | Cube.
- Create a C# script class named
PlayPauseMainTexture
and attach an instance...