Hi,
Apologies for any newbiness that follows. I’m new to Unity and new to this forum!
I’m working on integrating a cutscene into a project I’m working on. Using this tutorial I found, I’ve got the transition into the cutscene working. However, my method for getting out of the cutscene once the video has finished playing isn’t really working.
In the Playvideo.cs script from the link above, I’ve added an iTween.CameraFadeTo instruction to start a fade-out one second before the end of the video:
Code:
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()
{
iTween.Init(gameObject);
//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
float newHeight = -(Screen.height-(Screen.width/(mTex.width/(float)mTex.height)));
float yOffset = (-Screen.height-newHeight)/2;
videoGUItex.pixelInset = new Rect(Screen.width/2, yOffset,0,newHeight);
}
//On Script Start
void Start()
{
//set the videoGUItex.texture to be the same as mTex
videoGUItex.texture = mTex;
//Plays the movie
if (mTex.isReadyToPlay) {
mTex.Play();
//plays the audio from the movie
movieAS.Play();
// set up a fade-out for when the movie completes
iTween.CameraFadeAdd();
iTween.CameraFadeTo(
iTween.Hash(
"amount",1,
"time",1,
"delay",mTex.duration,
"onstart","onVideoPlaybackStart",
"oncomplete","onVideoPlaybackComplete"
)
);
}
}
void onVideoPlaybackStart()
{
Debug.Log("video fade-out starting");
}
void onVideoPlaybackComplete()
{
Debug.Log("video fade-out finishing");
Application.LoadLevel(0);
}
}
The fade-out works as expected, but the onstart and oncomplete functions don’t appear to - the Debug.Log messages don’t appear in my log. Does anyone see anything I’m doing wrong?