- Home /
On end of iTween
Is it possible to have something happen when this iTween ends:
function Start ()
{
iTween.moveTo( gameObject, { "x" : -1449.818 , "y" : 398.2629 , "z" : 1201.911 , "time" : Speed });
}
if it is how do I go about it
Answer by Tetrad · Jun 28, 2010 at 05:55 AM
http://itween.pixelplacement.com/ look at "Callback Functions"
Nearly all of the methods in iTween allow the addition of an optional "onStart" and "onComplete" argument. This argument takes a string refrence to an existing function in any script attached to the currently utilized GameObject. In addition, you can optionally provide "onStartParams" and/or "onCompleteParams" arguments to allow the passing of an object to the destination "onStart" or "onComplete" function. You can also specify an "onStartTarget" and/or "onCompleteTarget" to allow the firing of a function on a different GameObject.
To illustrate this functionality let's create a looping animation (Note: iTween includes a native loop feature called "loopType" built in which could have been set to "pingPong" to do this in 1 line of code but this example is merely to demonstrate the flexibility of utilizing callbacks):
private var tweenTarget : GameObject; var counter : GUIText; var count : int =0;
function Start(){ tweenTarget=gameObject; roll("right"); counter.guiText.material.color = Color.black; }
private function roll(direction: String): void{ switch(direction){ case "right": iTween.rotateBy(tweenTarget,{"z":-.5}); iTween.moveTo(tweenTarget,{"x":1.7, "onComplete":"roll", "onCompleteParams":"left"}); count+=1; break;
case "left":
iTween.rotateBy(tweenTarget,{"z":1});
iTween.moveTo(tweenTarget,{"x":-1.7, "onComplete":"roll", "onCompleteParams":"right"});
count+=1;
break;
}
counter.text=count.ToString() + " Loops";
}
Answer by qJake · Jun 28, 2010 at 05:07 AM
Reference: http://www.insquare.com/itween/
I think you can just layer them on top of each other, and they'll queue automatically. It's kinda weird, but it's easier than sticking it in a coroutine or something. Like this:
function Start ()
{
iTween.moveTo( gameObject, { "x" : -1449.818 , "y" : 398.2629 , "z" : 1201.911 , "time" : Speed });
iTween.moveTo( gameObject, { "x" : 0 , "y" : 0 , "z" : 0 , "time" : Speed });
}
yea, but what if I wont to say, Delete the object once its done? sorry I should have been more clearer in the question. :)
Yes, you should have. Look at the "Callback Functions" section of the iTween webpage, it describes how you can do that.
Answer by dentedpixel · Dec 17, 2012 at 07:45 PM
This is how you would accomplish the same task with LeanTween:
function Start ()
{
var toPoint = Vector3( -1449.818, 398.2629, 1201.911);
var speed = 1.0;
LeanTween.move( gameObject, toPoint, speed, {"onComplete":moveComplete});
}
function moveComplete(){
Debug.Log("I am done!");
}