iTween.CameraFadeTo not firing onstart/oncomplete

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?

I had the same problem today. Actually, what iTween does is to use the data you give to send a message to a specific GameObject once the trigger is activated (In this case it’s “onclomplete”). I managed to understand that by reading this part of the iTween Library:

if (tweenArguments.Contains(callbackType) && !tweenArguments.Contains("ischild")) {
		//establish target:
		GameObject target;
		if (tweenArguments.Contains(callbackType+"target")) {
			target=(GameObject)tweenArguments[callbackType+"target"];
		}else{
			target=gameObject;	
		}
		
		//throw an error if a string wasn't passed for callback:
		if (tweenArguments[callbackType].GetType() == typeof(System.String)) {
			target.SendMessage((string)tweenArguments[callbackType],(object)tweenArguments[callbackType+"params"],SendMessageOptions.DontRequireReceiver);
		}else{
			Debug.LogError("iTween Error: Callback method references must be passed as a String!");
			Destroy (this);
		}
	}

The problem in this case, arise when you don’t pass the "oncompletetarget" parameter to the iTween cameraFadeTo, since when it resolves the gameObject in the fuction that specific instance is the “iTween Camera Fade” object, which obviously doesn’t have the function you want to call.

To solve this you just have to pass the GameObject that has that specific function (i.e. gameObject). In this specific case the call should be:

iTween.CameraFadeTo(
        iTween.Hash(
            "amount",1,
            "time",1,
            "delay",mTex.duration,
            "onstart","onVideoPlaybackStart",
            "oncomplete","onVideoPlaybackComplete",
            "oncompletetarget", gameObject
        )
);

I hope this has solved your problem.

For onstart and oncomplete method you have to add its target after compeleted
use this :-

  iTween.CameraFadeTo(
             iTween.Hash(
                 "amount",1,
                 "time",1,
                 "delay",mTex.duration,
                 "onstart","onVideoPlaybackStart",
                 "onstarttarget",gameObject,
                 "oncomplete","onVideoPlaybackComplete"
                "oncompletetarget",gameObject
             )
         );