To use scripting to control video playback, follow these steps:
- Create a new Unity 3D project.
- Import the provided videoTexture.mov file.
- Create a 3D Cube by going to GameObject | 3D Object | Cube.
- Create a C# script class named PlayPauseMainTexture and attach an instance object as a component to your 3D Cube GameObject:
using UnityEngine;
using UnityEngine.Video;
[RequireComponent(typeof(VideoPlayer))]
[RequireComponent(typeof(AudioSource))]
public class PlayPauseMainTexture : MonoBehaviour {
public VideoClip videoClip;
private VideoPlayer videoPlayer;
private AudioSource audioSource;
void Start() {
videoPlayer = GetComponent<VideoPlayer>();
audioSource = GetComponent<AudioSource>();
// disable Play on Awake for both vide and audio
videoPlayer.playOnAwake = false;
audioSource.playOnAwake = false;
// assign video clip
videoPlayer.source = VideoSource.VideoClip;
videoPlayer.clip = videoClip;
// setup AudioSource...