- Home /
iTween value doesnt change
var dis:float;
function Update () {
iTween.MoveUpdate(gameObject,{"x":transform.position.x - dis});
}
I'm setting float "dis" from another script. At the begginning it's 6, but when I change it on runtime to 4 or something, iTween doesnt move object, it still uses value 6. I can see that value is changing on editor, but iTween still doesnt use the new value.
Is this somekind iTween bug? How I can fix this?
Answer by Catlard · Mar 05, 2013 at 02:43 PM
Why are you using MoveUpdate instead of MoveTo? Why are you using MoveUpdate without specifying an update function for the call to refer to?
Using the iTween.Hash function is good. Check that out.
Possible reason this is happening -- is it possible you are adjusting a public variable in the script, and not in the inspector? Make sure that the variable "dis" is private, and then try changing it again.
Let me know how it goes?
I'm using $$anonymous$$oveUpdate since $$anonymous$$oveTo is too laggy for my usage since i'm changing positions in realtime (Example on my first post is just example, it's not from my actual code). I dont understand what you mean with "Why are you using $$anonymous$$oveUpdate without specifying an update function for the call to refer to?", iTween documentation doesnt speak anything about specifying update functions.
I cant really change variable in inspector since variable value is defined on another script, for the same reason I cant put it private, cos other scripts cant find it then.
FIRST: Often, to keep variables "safe", I'll make them private, so they can't be seen/changed in the inspector. Then I create a "get" or "set" function -- something that just returns the value of the variable. They have this in c#, but you can make your own in Javascript. It makes things simpler in the long run. Often, the key to fixing bugs like this is to simplify your code by using tools like this. This thread will help you figure them out. :
http://forum.unity3d.com/threads/99568-UnityScript-Getter-Setter-Are-they-supposed-to-work
SECOND: It's true, the itween documentation doesn't really describe update functions very well. But here's an example of how my itween "update" functions work, in c#. ValueTo works the same way $$anonymous$$oveUpdate does. I'm sure you can see how it would work in java/unityscript. First, you have the itween call, which occurs somewhere in code.
iTween.ValueTo( _pageToScroll, iTween.Hash("from", _movementDir, "to", Vector3.zero, "islocal", true, "onupdatetarget", gameObject, "onupdate", "UpdateThrow", "time", Annotation$$anonymous$$itchen.instance._timeToStopDriftingAfterThrow , "easetype", Annotation$$anonymous$$itchen.instance._stoppingEaseTypeAfterThrowing, "oncompletetarget", gameObject, "oncomplete", "StopDrifting" ));
In that code, there's a reference to an "onupdate" function called "UpdateThrow". That function looks like this:
public void UpdateThrow( Vector3 newValue )
{ }
The "newValue" accepted by the function "UpdateThrow" is the updated value. Just make sure that you also specify the "onupdatetarget" in the itween call. Otherwise it won't work.
Does that help?
Your answer
![](https://koobas.hobune.stream/wayback/20220613093849im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
iTween MoveTo: Object doesn't quite reach the target position 0 Answers
Rotation 90.0001 and 1.001719 bugs! 1 Answer
How can I use iTween to tween the color of a SpriteRenderer? 1 Answer
I can not start, any stopped of itween 1 Answer
Itween, how to mouseclick movement on 3rd person camera 2 Answers