-
-
Save mnjstwins/99d06689a1b967bb870268f87abef5f8 to your computer and use it in GitHub Desktop.
Playing a video with the new VideoPlayer component with Unity 5.6 beta.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class VideoManager : MonoBehaviour | |
| { | |
| [SerializeField] | |
| private RenderTexture _renderTexture = null; | |
| [SerializeField] | |
| private VideoClip _videoClip = null; | |
| private IEnumerator Start() | |
| { | |
| Application.runInBackground = true; | |
| var camera = Camera.main.gameObject; | |
| var videoPlayer = camera.AddComponent<VideoPlayer>(); | |
| var audioSource = camera.AddComponent<AudioSource>(); | |
| videoPlayer.playOnAwake = false; | |
| audioSource.playOnAwake = false; | |
| videoPlayer.source = VideoSource.VideoClip; | |
| videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource; | |
| videoPlayer.renderMode = VideoRenderMode.RenderTexture; | |
| videoPlayer.EnableAudioTrack(0, true); | |
| videoPlayer.SetTargetAudioSource(0, audioSource); | |
| videoPlayer.clip = _videoClip; | |
| videoPlayer.Prepare(); | |
| while (!videoPlayer.isPrepared) | |
| yield return null; | |
| videoPlayer.targetTexture = _renderTexture; | |
| videoPlayer.Play(); | |
| audioSource.Play(); | |
| while (videoPlayer.isPlaying) | |
| yield return null; | |
| ScreenFader.FadeIn(2.5f, () => SceneManager.LoadScene("Menu")); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment