Author Topic: Change widget anchor in c# at runtime  (Read 7051 times)

SquigglyFrog

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Change widget anchor in c# at runtime
« on: July 11, 2014, 12:22:56 AM »
Ok, I am still really new to NGUI and unity in general.. Currently I have a button inside a UIPanel.. it is anchored to the bottom left.  Anchor type shows unified.. How can I change that anchorposition in c# to anchor it to the bottom right? Been trying for a bit and nothing seems to get that to move.. I could always create a separate duplicate button, but I know there has to be a better way to just move it to the other side of the screen...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change widget anchor in c# at runtime
« Reply #1 on: July 11, 2014, 07:55:39 PM »
widget.leftAnchor.Set(target, 1, -100); // <-- '1' means 'right', as 0 is 'left' and 0.5 is 'center'. -100 is the absolute offset -- 100 pixels.

You will need to set others as well (rightAnchor, topAnchor, bottomAnchor).

SquigglyFrog

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Change widget anchor in c# at runtime
« Reply #2 on: July 11, 2014, 10:59:27 PM »
That could be where I was going wrong then,  inputting wrong values in the set.  Will give this a try once I  get home. Hopefully that will take care of my issue.  I'm assuming I will need to call reset and update anchors as well. One other question,  target.  Is this just my current gameobject or?

Appreciate the assistance!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change widget anchor in c# at runtime
« Reply #3 on: July 12, 2014, 03:59:20 PM »
Target is whatever you want this widget to be anchored to.