Author Topic: AnchorPoint targets not properly set in code?  (Read 3820 times)

lataupe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
AnchorPoint targets not properly set in code?
« 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 :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: AnchorPoint targets not properly set in code?
« Reply #1 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?

lataupe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: AnchorPoint targets not properly set in code?
« Reply #2 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 :-)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: AnchorPoint targets not properly set in code?
« Reply #3 on: December 12, 2013, 01:18:29 PM »
You can grab the latest (f2) and call ResetAnchors() function to accomplish what you want.

lataupe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: AnchorPoint targets not properly set in code?
« Reply #4 on: December 13, 2013, 11:28:29 AM »
perfect.Thank you very much.
What a proactive developer ;-)