Easy to use videoplayer.js script for Unity.

Hey guys, I’ve seen quite a few posts about playing a full screen video in unity, presumably to give the ability to play a FMV.

I decided to post this little script you can add to a component in order to play a full screened gui movie.

var texture : Texture; 
var pause = 0.0; 
var scenename = "SceneName"; 

function Start () {
renderer.material.mainTexture.Play();

}
function OnGUI()
{
GUI.DrawTexture(Rect(0.0f, 0.0f, Screen.width, Screen.height), texture);
}


print ("VideoPlaying");
yield WaitForSeconds (pause);

Application.LoadLevel(scenename);


function Update () {

}

All you need to do to get this working is to link the texture you want to play, tell the script how long the video is by adding in a pause value and adding the scene you want to load after the video is complete!

I hope this helps someone out!

The WaitForSeconds call should be in a function. Don’t put code in random places. Plus, you should make sure you actually have a VideoTexture rather than a normal texture before you tell it to play.