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");
    }

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!

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);
> 
> 
> 	}

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.
:slight_smile: