- Home /
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?
Answer by hiddenspring81 · May 28, 2013 at 02:02 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103055im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
iTween - look for new path, move to or reverse at end? 0 Answers
ITween orienttopath x-y-z? 1 Answer
How do you create random paths in iTween? 0 Answers
how to cancel iTween Catmull-Rom path 1 Answer
iTween even velocity 9 Answers