Created
October 27, 2016 19:23
-
-
Save vicenterusso/49051d39cf8d1ca8fd2accd2dd8d2964 to your computer and use it in GitHub Desktop.
UI Canvas Movie Unity3D
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
| using UnityEngine; | |
| using UnityEngine.UI; | |
| using System.Collections; | |
| using DG.Tweening; | |
| [RequireComponent(typeof(AudioSource))] | |
| public class PlayMovie : MonoBehaviour | |
| { | |
| public MovieTexture Movie; | |
| internal AudioSource AudioSource; | |
| void Awake() | |
| { | |
| var listener = FindObjectOfType<AudioListener>(); | |
| if (!listener) gameObject.AddComponent<AudioListener>(); | |
| } | |
| void Start () | |
| { | |
| Application.targetFrameRate = 30; | |
| var rawImage = GetComponent<RawImage>(); | |
| AudioSource = GetComponent<AudioSource>(); | |
| AudioSource.volume = Toolbox.Instance.VolumeMusic; | |
| rawImage.color = Color.white; | |
| rawImage.texture = Movie as MovieTexture; | |
| StartCoroutine("StartMovie"); | |
| } | |
| IEnumerator StartMovie() | |
| { | |
| while (!Movie.isReadyToPlay) | |
| yield return null; | |
| Movie.Play(); | |
| AudioSource.Play(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment