Hi
I am new to NGUI… I just watn to tween a gameobject from 1 position to another.
I know I can do using TweenPosition script and filling in the values…
I know I can do using TweeenPosition.Begin method…
But I donn’t know how to use TweenPosition class all features through scripting like
onFinished delegate and Tweeinng style…
If someone can plz show me an example…
I am doing something like this…
TweenPosition obj = new TweenPosition();
obj.from = new Vector3(5.960464e-08f, 260, 0);
obj.to = new Vector3(5.960464e-08f, 105, 0);
obj.style = UITweener.Style.Once;
obj.steeperCurves = true;
obj.method = UITweener.Method.EaseIn;
but I can’t find how to play the tween and set the onFinished delegate…
I don’t know why you would want to create a TweenPosition object, but anyway…
First things first, here’s how you normally use TweenPosition (which is something you said you know, but just to keep everything in one place):
To tween a gameObject go, from its current position to position pos during t:
TweenPosition.Begin(go, t, pos);
Now, immediately using this notation, you could subscribe to the onFinished event by:
TweenPosition.Begin(go, t, pos).onFinished += OnAnimFinishedHandler; // this is ok because Begin here returns a TweenPosition object, from which you could access onFinished
public void OnAnimFinishedHandler(UITweener tweener) // your handler must have this signature (a UITweener param)
{
// do whatever you want
}
If you want to do everything manually, just create a TP object, set its from and to, the style, method, etc. When you’re done, call Play to start the tweening process. You could at anytime Reset it, or Toggle it.
var tp = new TweenPosition();
tp.from = transform.position;
tp.to = someOtherVector;
tp.style = UITweener.Style.Once; // there's also PingPong (back and forth) and Loop (when reaches end, goes back to start)
tp.method = UITweener.Method.EaseIn; // there's also BounceIn, BounceOut, EaseOut, etc
tp.onFinished += myHandler;
tp.duration = t;
tp.Start(); // at anytime you could reset it, using tp.Reset() getting it back to the beginning; or toggle it tp.Toggle(); reversing it