One of the most frequent problems I see people have with iTween is with callbacks that don’t fire.

At it’s core iTween leverages Unity’s SendMessage method
for carrying out it’s 3 callbacks: “onStart”, “onUpdate” and “onComplete”. When you add an iTween to a GameObject, iTween will throw all callbacks against the GameObject that is being animated. Where most people have difficulties is when they assign iTweens
to GameObjects that don’t physically contain the methods they are attempting to call.

For example, the following code with never execute the “ShakeComplete” method because the “target” GameObject does not have a script attachted to it containing this method:

using UnityEngine;
using System.Collections; public class UnderstandingCallbacks : MonoBehaviour
{
public GameObject target; void Start ()
{
iTween.ShakePosition(target, iTween.Hash("x", 1, "onComplete", ShakeComplete));
} void ShakeComplete(){
Debug.Log("The shake completed!");
}
}

There’s 2 ways to correct the previous script. The long route: create another script, attach it to our actual “target” GameObject and transfer the “ShakeComplete” method to that new script. The easy route: utilize iTween’s callback “target modifiers”!

Each of iTween’s 3 callbacks have an additional “target modifier” that can be used to tell iTween to look somewhere else for the callback method: “onStartTarget”, “onUpdateTarget” and “onCompleteTarget”.

The following corrected script will now fire the “onComplete” callback since we are now using “onCompleteTarget” to tell iTween that the “ShakeComplete” method is located on the GameObject that actually set up the iTween:

using UnityEngine;
using System.Collections; public class UnderstandingCallbacks : MonoBehaviour
{
public GameObject target; void Start ()
{
iTween.ShakePosition(target, iTween.Hash("x", 1, "onComplete", "ShakeComplete", "onCompleteTarget", gameObject));
} void ShakeComplete(){
Debug.Log("The shake completed!");
}
}

I hope this helps clear up unsuccessful callbacks in iTween.

UNDERSTANDING ITWEEN CALLBACKS的更多相关文章

  1. Understanding Asynchronous IO With Python 3.4's Asyncio And Node.js

    [转自]http://sahandsaba.com/understanding-asyncio-node-js-python-3-4.html Introduction I spent this su ...

  2. [转] Understanding JavaScript’s async await

    PS:Promise的用处是异步调用,这个对象使用的时候,call then函数,传一个处理函数进去,处理异步调用后的结果 Promise<Action>这样的对象呢,异步调用后的结果是一 ...

  3. Understanding JavaScript Function Invocation and "this"

    Understanding JavaScript Function Invocation and "this" 11 Aug 2011 Over the years, I've s ...

  4. Async Performance: Understanding the Costs of Async and Await

    Stephen Toub Download the Code Sample Asynchronous programming has long been the realm of only the m ...

  5. jquery.Callbacks的实现

    前言 本人是一个热爱前端的菜鸟,一直喜欢学习js原生,对于jq这种js库,比较喜欢理解他的实现,虽然自己能力有限,水平很低,但是勉勉强强也算是能够懂一点吧,对于jq源码解读系列,博客园里有很多,推荐大 ...

  6. 解决ugui中Image使用iTween的ColorTo、ColorFrom等不生效

    查看iTween的源码找到ColorFrom函数,看该函数的注释“/// Changes a GameObject's color values instantly then returns them ...

  7. GOOD MEETINGS CREATE SHARED UNDERSTANDING, NOT BRDS!

      Deliverables and artifacts were a focal point of BA work during the early part of my career. If I ...

  8. jQuery.Callbacks之demo

    jQuery.Callbacks是jquery在1.7版本之后加入的,是从1.6版中的_Deferred对象中抽离的,主要用来进行函数队列的add.remove.fire.lock等操作,并提供onc ...

  9. jQuery 2.0.3 源码分析 回调对象 - Callbacks

    源码API:http://api.jquery.com/jQuery.Callbacks/ jQuery.Callbacks()是在版本1.7中新加入的.它是一个多用途的回调函数列表对象,提供了一种强 ...

随机推荐

  1. doT.js模板和pagination分页应用

    doT.js模板和pagination分页应用 博客中模拟了数据加载初始化的过程.doT.js渲染每一项内容的数据项.示例如下: <script id="Messtmpl" ...

  2. Mac 安装 Jenkins

    Mac 安装 Jenkins 有两种方法 方法一: 从官方下载最新版本:http://mirrors.jenkins-ci.org/osx/latest 点击安装. 方法二(推荐): 使用 homeb ...

  3. session一直报错Session store not set on request

    Route::group(['middleware' => ['web']], function () { //});仍然报错,看了 session是使用默认file,没问题:app/stora ...

  4. 【IBM-WALA】Step by Step : use WALA to generate System Dependency Graph PDF and Dot File (Mac)

    Preparations: 1. IDE : eclipse (my version is luna) 2. maven (my version is 3.5.0) 3. git 4. JAVA 1. ...

  5. 解决在html中引入font-awesome的css文件后, 图标显示不出来

    今天小颖在做项目时,需要在html文件中引入font-awesome.min.css,但是引入后: 以前小颖在用font-awesome库里的图标时,都是直接从node中下包,然后在main.js中引 ...

  6. DAX Editor VSIX project

    DAX Editor is a Visual Studio extension that implements a language service for DAX language for SQL ...

  7. Linux搭建Socks5代理服务器

    下面笔者将用SS5在亚马逊云服务器上的Linux搭建一台Socks5 Proxy Server,具体过程如下: 1.首先,编译安装SS5需要先安装一些依赖组件 yum -y install gcc g ...

  8. 引用了System.Configuration命名空间,却找不到ConfigurationManager类

    用ConfigurationManager类来读取应用程序配置文件的信息时,提示:System.Configuration命名空间下找不到ConfigurationManager类 查过资料后得知:要 ...

  9. MyEclipse中的几种查找方法

    在编程中常常需要用到查找功能,这里根据日常的使用总结一下常用的集中查找方法 Ctrl+H:在MyEclipse中打开Search弹出框,或者在菜单中打开Search弹出框, 定位到 File Sear ...

  10. CH 1402 - 后缀数组 - [字符串hash]

    题目链接:传送门 描述 后缀数组 (SA) 是一种重要的数据结构,通常使用倍增或者DC3算法实现,这超出了我们的讨论范围. 在本题中,我们希望使用快排.Hash与二分实现一个简单的 $O(n \log ...