Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: SquigglyFrog on July 11, 2014, 12:22:56 AM

Title: Change widget anchor in c# at runtime
Post by: SquigglyFrog 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...
Title: Re: Change widget anchor in c# at runtime
Post by: ArenMook 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).
Title: Re: Change widget anchor in c# at runtime
Post by: SquigglyFrog 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!
Title: Re: Change widget anchor in c# at runtime
Post by: ArenMook on July 12, 2014, 03:59:20 PM
Target is whatever you want this widget to be anchored to.