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. 九、K3 WISE 开发插件《工业单据老单序时薄插件工具栏按钮开发实例》

    =============================== 目录: 1.添加工具栏按钮 2.查询被添加工具栏按钮的业务单据的FMenuID和FID 3.添加工具栏按钮和业务单据的映射关系 4.工具 ...

  2. NIO相关概念之Buffer

    Buffer的定义: 概念上,缓冲区是包在一个对象内的基本数据元素数组.Buffer类相比一个简单数组的优点是它将关于数据的数据内容和信息包含在一个单一的对象中.Buffer类以及它专有的子类定义了一 ...

  3. Linux----知识储备

    ----------------------------------------------------------------------基础---------------------------- ...

  4. 关于Dosbox0.74无法使用masm命令

    今天尝试在dosbox里编译asm源代码文件 但是提示“illegal command”,也就是非法命令 开始还以为我的dosbox版本不对 但是去网上查阅资料发现别人用这个版本都可以使用 所以百思不 ...

  5. python中的str和repr函数的区别

    看了一些网上的解释,最主流的解释是“str是给人看的,repr是给机器看的”,如果已经理解了的,这句话是对的,但是是有问题的,对于没懂的,这句话是无法理解的. 我来尝试解释一下.先直译一下官方文档: ...

  6. HDU 1506 & 1505 - Largest Rectangle in a Histogram & City Game

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  7. angular 表单元素的使用总结

    工作中form表单元素最常用的是input,问题没有太多,现在总结下select ,radio组,checkbox的使用 1 select 常用的使用方式,如下 var Cityis = [{id:0 ...

  8. [CentOS7][ssh][publickey][troubleshoot] 通过密钥登录ssh故障排查

    通常情况下,我会使用非对称加密的方式来进行ssh的登录. 做法: 将公钥添加到 $HOME/.ssh/authorized_keys 文件中. 但是通常,会遇见各种各样的问题,导致失败.汇总如下: 0 ...

  9. MiniHook研究

    git hub 地址: https://github.com/RaMMicHaeL/minhook

  10. dp进阶——饥饿的奶牛

    饥饿的奶牛oj上n只有1000,过于水,O(n^2)的算法很容易水过,洛谷上这是一道提高加的题,很难啊,所以要好好拿来练习今天写博客再次复习一下,oi最怕遗忘了. 这道题呢实质是一个区间覆盖的dp,首 ...