Unity3D:iTween oncomplete 不工作

Unity3D: iTween oncomplete not working

我正在开发 Unity2 游戏,我想让 Boom 在 iTween 动画结束时消失。

这是部分代码

void OnMouseDown() {    

    if (ChosePosition == false)
        ChosePosition = true;

    // make Star stop
    else if (ChosePosition == true && ChoseForce == false) {
        ChoseForce = true;
        //Compute Force power 
        PowerDegree = Mathf.Abs (Star.transform.position.y - StarPosition)/ Mathf.Abs(StarendPosition - StarPosition) * 100;

        //print (PowerDegree);

        Vector3 NewBoomPostion = new Vector3 (Luncher.transform.position.x, BoomPosition, 85);

        GameObject newBoom = Instantiate(Boom, NewBoomPostion , Quaternion.identity) as GameObject;
        iTween.MoveTo (newBoom, iTween.Hash 
            ("y",BoomPosition+((BoomendPosition-BoomPosition)/100*PowerDegree),
            "speed",Boomspeed,
            "EaseType",BoomeaseType,
            "LoopType",BoomloopType,
            "oncomplete","BoomComplete"
            ));


        CarrierReset = true;
        ChosePosition  = false;
        ChoseForce = false;

        //After Shot, Luncher will move
        iTween.Resume(Luncher);

        //After Shot, Luncher Carrier will display
        displayCarrierOrNot = true;
    }
}


void BoomComplete(){
    print("complete");
}

但我在控制台中看不到 "complete"。

This post 在 Unity Answers 上描述了您遇到问题的原因:

By default iTween attempts to call the callback methods you provide it on the object it is animating - in your case the mainCamera.gameObject. Since "onCameraShakeComplete" does not reside on that object it is never getting called. You have two options: Move that method onto your mainCamera.gameObject or simply provide am "onCompleteTarget" of gameObject to tell iTween to use the GameObject that is setting up this iTween.

在你的情况下,它正在动画的对象是 newBoom,但你有自己的组件回调。要让 iTween 使用您当前的回调,您可以在 Hash 调用中添加一个参数:

iTween.MoveTo (newBoom, iTween.Hash(
    // ...
    "oncomplete", "BoomComplete",
    "oncompletetarget", gameObject
    ));