- Home /
NGUI TweenPostion..
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..
Why NGUI for this simple thing..?Vector3.Lerp() will do right..?
Vertor3.Lerp doesn't contains Lerp Finished event..dats y..
You can use the TimeValue in lerp to check for lerp completion. Vector3.Lerp(from,to,TimeValue); if(TimeValue>=1) { //Do here for lerp completion. }
Hope this helps...... :-)
Answer by vexe · Oct 02, 2013 at 10:00 PM
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
That's pretty much it.
Answer by vanshika · Dec 17, 2013 at 02:16 PM
Hi I want to do the same, But not able to crack it. I want to use TweenPosition.Begin but just add on feature to method.