- Home /
Using iTween for custom variables
I am looking for a way to use iTween to ease the values of some custom variables on one of my scripts. It looks like ValueTo() is similar to what I would want, but I cannot figure out how to pass in a reference to the script as it is not a GameObject.
Example:
public class SampleClass : MonoBehaviour {
public float sampleValue = 0.0f;
}
SampleClass would be attached to a game object. I would like to ease sampleValue.
Answer by Nerull22 · Aug 31, 2011 at 01:01 AM
In cases like this, you can use something like this:
iTween.ValueTo(gameObject, iTween.Hash(.....));
Specifically type in "gameObject". See if that works for you.
Answer by Malcolm · Aug 31, 2011 at 01:26 AM
That works perfectly thank you.
Code snippet in case anyone else needs a reference of how to use:
public class TweenTest:MonoBehaviour {
public float someValue = 0.0f;
public void Start () {
Hashtable param = new Hashtable();
param.Add("from", 0.0f);
param.Add("to", 10.0f);
param.Add("time", 10.0f);
param.Add("onupdate", "TweenedSomeValue");
iTween.ValueTo(gameObject, param);
}
public void TweenedSomeValue(float val){
someValue = val;
}
}
That's useful thanks. You can also use the iTween.Hash() method to avoid instantiating a HashTable.
Answer by TimK.Disney · Apr 17, 2013 at 01:07 AM
Word to the wise: Do not use "TweenUpdate" as your callback function name. That is a function in the iTween library that is in the call stack leading to the value tween update call. Doing this will cause your tween to recurse infinitely, will cause Unity to blow its stack and hang (boo, Unity! Ought to nuke any scripts in which stack depth exceeds a certain value!) and will leave you scratching your head going "wtf"?