RSS

iTween onComplete event handler example

14 Dec

iTween is a handy library to implement tween/ease type animations. One of the useful callback it provides is the onComplete event. Below is an example code of how to use it:

iTween.MoveTo(lotus_leaf, iTween.Hash(
                      “y”, 80f,
                      “onComplete“, “OnShadeHidden”)
             );

void OnShadeHidden()
{
        Debug.Log(“The shade is hidden”);
        lotus_leaf.SetActive(false);
}

where lotus_leaf is the game object to be tweened in y position, and OnShadeHidden() is the callback function or event handler.

However if you run this code, you will see the callback OnShadeHidden is NOT fired when the tween is completed! The reason is that iTween needs another parameter: onCompleteTarget, to specify which object handles the onComplete event, so the right way to get it done will be like this:

iTween.MoveTo(lotus_leaf, iTween.Hash(
                      “y”, 80f,
                      “onComplete“, “OnShadeHidden”,
                      “onCompleteTarget“, gameObject)
             );

Run the code, the onComplete event handler will be properly addressed. Happy coding!

Advertisements
 
1 Comment

Posted by on December 14, 2014 in Unity 3d

 

Tags: , , , , , , , , ,

One response to “iTween onComplete event handler example

  1. Muser

    September 1, 2017 at 5:37 pm

    You are the man!

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: