Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: eppz! on July 21, 2016, 04:35:10 PM

Title: Change UIWidget anchor target on the fly?
Post by: eppz! on July 21, 2016, 04:35:10 PM
I have a moving (scrolling) widget, and I want to "stick" some sprite to it at a certain time.

I did this...

  1. void Update()
  2. {
  3.         Transform target = (followPushTransform) ? layout.pushTransform : layout.anchorTransform;
  4.         sprite.topAnchor.target = target;
  5.         sprite.bottomAnchor.target = target;
  6. }

...but the sprite refused to move along the widget. I can see the targets update just right on the inspector, but the sprite don't get "stuck". Should I call some widget call on the sprite after adjustment (I tried `UpdateAnchors` with no luck)?
Title: Re: Change UIWidget anchor target on the fly?
Post by: ArenMook on July 24, 2016, 06:35:58 AM
While you can use SetAnchor(target) with optional offset parameters, the easiest thing to do is to reparent the sprite to the widget so that it always moves with it.