- Home /
iTween oncomplete not firing
Hey guys, quick question. I have the following method that fires a camera shake using iTween. I set the oncomplete property to a method inside the same class but it doesn't seem to be firing. Here is what I have. I'm sure I'm missing something but I can't seem to see what.
public void CameraShake(float magnitude, float duration) {
cameraShaking = true;
Hashtable ht = new Hashtable();
ht.Add("x", magnitude);
ht.Add("y", magnitude);
ht.Add("time", duration);
ht.Add("oncomplete", "onCameraShakeComplete");
iTween.ShakePosition(mainCamera.gameObject, ht);
}
public void onCameraShakeComplete()
{
cameraShaking = false;
print("Done");
}
Answer by pixelplacement · Feb 04, 2011 at 05:07 PM
If I had $1 for every time this has been asked!
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.
Hope that helps.... I hate typing this answer up ;)
Good luck!
Really sorry, but thanks for the reply. I appreciate it.
I am sure people ask this a lot!!! but i can not make it work with the visual editor. I put my iTween name in the oncomplete spot and then drag the object that contains the iTween into the target spot and nothing happens.... Even if both iTweens are on the same object it still does not work
Ok now i can get an iTween to run with the OnComplete if it is on the same object by not specifying an object at all... i was dragging the object onto the variable even if it was the same one... But i still cant get it to work if the iTween is on a different object even if i drag out the target object variable.. And why does the iTween start right away when it is specified with the OnComplete function? That messed me up as well. I thought it was not working until i put a few second delay on the second iTween then i realized it was just firing right away ins$$anonymous$$d of after the first one was done
Ok i take it back the running a second iTween from OnComplete that is on the same object is not working the reason it was firing right away was because i was calling it from my other script. So my question still is why cant i get the OnComplete to work from the visual editor?
Answer by humam · Sep 19, 2014 at 02:06 PM
even after adding "oncompletetarget" , mainDraggablePannel.gameObject
i couldnt achieve the result.... since my i had a seperate script object.... for that i changed it to "oncompletetarget",this.gameObject
and it worked!!
> public void onBackButtonPressed(){
>
> iTween.MoveTo
> (mainDraggablePanel.gameObject,
> iTween.Hash
> ("x",0.0f/*mainDraggablePanel.transform.localPosition.x-UICamera.lastHit.collider.transform.localPosition.x*/,
> "y",0.0f,
> "time", 1.5f,
> "easetype",
> iTween.EaseType.easeOutQuad ,
> "oncomplete" , "ScaleDownOnZoomOut" ,
> "oncompletetarget" , this.gameObject
> /*iTween.EaseType.easeInOutElastic*/));
>
>
> backButton.SetActive (false); }
>
> public void ScaleDownOnZoomOut(){
> Debug.Log("yolo");
iTween.ScaleTo
> (mainDraggablePanel.gameObject,
> Vector3.one, 2.5f);
>
>
> }
Thank you! That solved it for me!... "oncompletetarget",this.gameObject
Answer by umair_hassan · Apr 15, 2015 at 12:43 PM
Refer a gameobject on which current script is attached in your code.
iTween.ScaleBy(enemy[value], iTween.Hash("x", 0.5,"y",0.5, "delay", .1,"oncomplete", "kill","oncompletetarget",gm));
here gm is a gameobject on which your script is attached. :)
here gm is a gameobject on which your script is attached. :)
Thank You @umair_hassan :)
Your answer
Follow this Question
Related Questions
iTween a few questions 0 Answers
Collision Detection does not work in my scene 1 Answer
iTween how to define what object will be tweened 1 Answer
Camera shaking and parent movement 1 Answer