Author Topic: Change UIWidget anchor target on the fly?  (Read 916 times)

eppz!

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 6
    • View Profile
Change UIWidget anchor target on the fly?
« 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)?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: Change UIWidget anchor target on the fly?
« Reply #1 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.