Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: lataupe on December 11, 2013, 12:42:17 PM

Title: AnchorPoint targets not properly set in code?
Post by: lataupe on December 11, 2013, 12:42:17 PM
Hi,

I have tried to change the target of all the anchorpoints of a sprite in code which happens on click.

  1. objSpr.leftAnchor.target = firstEmptyCase.transform;
  2. objSpr.rightAnchor.target = firstEmptyCase.transform;
  3. objSpr.topAnchor.target = firstEmptyCase.transform;
  4. objSpr.bottomAnchor.target = firstEmptyCase.transform;

I believe this is the right way to do this as when running, in the inspector, i see the target change. but in fact, in the scene, it doesn't change. If i manually change the target to anything else and back to the right transform, it works.
I don't see why it behaves that way.

If you need any more details or if i'm not clear enough, ask :)
Title: Re: AnchorPoint targets not properly set in code?
Post by: ArenMook on December 12, 2013, 01:29:44 AM
You are doing it the right way, but without calling the CacheAnchors() function (which is protected), there won't be any visible effect.

Why are you doing this anyhow?
Title: Re: AnchorPoint targets not properly set in code?
Post by: lataupe on December 12, 2013, 11:55:27 AM
Thank you for your reply. I'm doing this to "put" a sprite of any size in a cell so that it fills the whole cell. But if there is a better way to do this, I'd be glad to know it :-)
Title: Re: AnchorPoint targets not properly set in code?
Post by: ArenMook on December 12, 2013, 01:18:29 PM
You can grab the latest (f2) and call ResetAnchors() function to accomplish what you want.
Title: Re: AnchorPoint targets not properly set in code?
Post by: lataupe on December 13, 2013, 11:28:29 AM
perfect.Thank you very much.
What a proactive developer ;-)