iTween ValueTo not working

Hi there,

I’m currently using multiple iTween paths to control my camera’s location. (C# script).

I have two separate functions that handle different ValueTo commands:

public float percentageA = 0f;
public float percentageB = 0f;
public float EasingSpeedA = 1f;
public float EasingSpeedB = 1f;
public GameObject gObjectA;
public GameObject gObjectB;
public Transform [] RailA;
public Transform [] RailB;

void Update()
{
iTween.PutOnPath(gObjectA,RailA,percentageA);
iTween.PutOnPath(gObjectB,RailB,percentageB);
}

public void SlideATo(float position)
	{
Debug.Log("B " + position);
	iTween.ValueTo(gObjectA,iTween.Hash("from",percentageA,"to",position,"time",EasingSpeedA,"easetype",iTween.EaseType.easeInOutCubic,"onupdate","SlideAPercentage"));	
	}
	
void SlideAPercentage(float p)
{
	percentageA=p;
}

public void SlideBTo(float position)
	{
Debug.Log("B " + position);
	iTween.ValueTo(gObjectB,iTween.Hash("from",percentageB,"to",position,"time",EasingSpeedB,"easetype",iTween.EaseType.easeInOutCubic,"onupdate","SlideBPercentage"));	
	}
	
void SlideBPercentage(float p)
{
	percentageB=p;
}

Now in another script I am calling both the SlideATo and SlideBTo functions at different times, and can even get to the point where both Debug.Log messages can be made to appear; however, for some reason I can get ‘percentageB’ to change using the ValueTo command, but not ‘percentageA’.

Can anybody tell me what I might be doing wrong?

Be careful when setting up callbacks for iTween. Any callbacks for onupdate, onstart, oncomplete, etc. will be invoked on the target GameObject, and not on the script that was setting up the ValueTo tween. For example, the callbacks for

iTween.ValueTo(gObjectB,iTween.Hash("from",percentageB,"to",position,"time",EasingSpeedB,"easetype",iTween.EaseType.easeInOutCubic,"onupdate","SlideBPercentage"));

Will be invoked on gObjectB, but you callback methods were defined on a script, attached to gameObject. You can override this behavior by supplying the onupdatetarget parameter (there are similarly named parameters for other events too), which will redirect the iTween callback to a GameObject of your choosing. Your code will then become

iTween.ValueTo(gObjectB,iTween.Hash("from",percentageB,"to",position,"time",EasingSpeedB,"easetype",iTween.EaseType.easeInOutCubic,"onupdate","SlideBPercentage","onupdatetarget",gameObject));

This code is untested, but it should give you an idea about how to solve the problem.