- Home /
Question by
noelian13 · Jan 20, 2015 at 11:43 AM ·
sceneselectionmovietexture
How to go to next scene after the movie played and or if a key was pressed
I successfully played my movie, but now i want to go to the next scene after it played or the skip option by a button how can i implement it on a this script? thanks
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (GUITexture))]
[RequireComponent (typeof (AudioSource))]
public class PlayVideo : MonoBehaviour
{
//the GUI texture
private GUITexture videoGUItex;
//the Movie texture
private MovieTexture mTex;
//the AudioSource
private AudioSource movieAS;
//the movie name inside the resources folder
public string movieName;
void Awake()
{
//get the attached GUITexture
videoGUItex = this.GetComponent<GUITexture>();
//get the attached AudioSource
movieAS = this.GetComponent<AudioSource>();
//load the movie texture from the resources folder
mTex = (MovieTexture)Resources.Load(movieName);
//set the AudioSource clip to be the same as the movie texture audio clip
movieAS.clip = mTex.audioClip;
//anamorphic fullscreen
videoGUItex.pixelInset = new Rect(Screen.width/2, -Screen.height/2,0,0);
}
//On Script Start
void Start()
{
//set the videoGUItex.texture to be the same as mTex
videoGUItex.texture = mTex;
//Plays the movie
mTex.Play();
//plays the audio from the movie
movieAS.Play();
}
IEnumerator waitForMovieEnd()
{
while(mTex.isPlaying) // while the movie is playing
{
yield return new WaitForEndOfFrame();
}
// after movie is not playing / has stopped.
onMovieEnded();
}
void onMovieEnded()
{
Debug.Log("Movie Ended!");
Application.LoadLevel("MainScene");
}
}
Comment