Thursday, March 3, 2016

Video Texture in Unity

Here's the link to the Unity reference for how to do Movie Textures (aka how to put videos in Unity): http://docs.unity3d.com/Manual/class-MovieTexture.html. Below is the script that you need to play the movie with audio once the texture is assigned to an object (you must also add an Audio Source to your object):


using UnityEngine;
using System.Collections;

public class Video : MonoBehaviour {

 void Start () {
        ((MovieTexture)GetComponent<Renderer>().material.mainTexture).Play();
  AudioSource audio = GetComponent<AudioSource>();
  audio.clip = ((MovieTexture)GetComponent<Renderer>().material.mainTexture).audioClip;
  audio.Play ();
    }
}

-Reposted from Piazza

No comments:

Post a Comment