x


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.

more ▼

asked Aug 24 '11 at 07:14 PM

Malcolm gravatar image

Malcolm
47 4 4 5

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Aug 31 '11 at 01:01 AM

Nerull22 gravatar image

Nerull22
48 2 4 4

(comments are locked)
10|3000 characters needed characters left

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;
      }
}
more ▼

answered Aug 31 '11 at 01:26 AM

Malcolm gravatar image

Malcolm
47 4 4 5

That's useful thanks. You can also use the iTween.Hash() method to avoid instantiating a HashTable.

May 12 at 09:47 AM philjhale
(comments are locked)
10|3000 characters needed characters left

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"?

more ▼

answered Apr 17 at 01:07 AM

TimK.Disney gravatar image

TimK.Disney
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4172
x3806
x3744
x426

asked: Aug 24 '11 at 07:14 PM

Seen: 2555 times

Last Updated: May 12 at 09:47 AM