Skip to content

Instantly share code, notes, and snippets.

@vicenterusso
Created October 27, 2016 19:23
Show Gist options
  • Select an option

  • Save vicenterusso/49051d39cf8d1ca8fd2accd2dd8d2964 to your computer and use it in GitHub Desktop.

Select an option

Save vicenterusso/49051d39cf8d1ca8fd2accd2dd8d2964 to your computer and use it in GitHub Desktop.
UI Canvas Movie Unity3D
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