Author Topic: How to remove an Anchor in code  (Read 15812 times)

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
How to remove an Anchor in code
« on: August 27, 2015, 01:05:16 AM »
Hi, I have a game object with a sprite attached which I position on screen using anchors, I then disable the game object and use it as a template in code to add child to the scene. After adding the first child I want to remove the anchor on the template object.

There seems to be UIRect commands for setting the anchor but none to remove or disable it.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: How to remove an Anchor in code
« Reply #1 on: August 27, 2015, 01:09:22 AM »
the reset call might be redundant, idk.

  1. if (instance.background.isAnchored)
  2. {
  3.         instance.background.SetAnchor((Transform)null);
  4.         instance.background.ResetAndUpdateAnchors();
  5. }
  6.  

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
Re: How to remove an Anchor in code
« Reply #2 on: August 27, 2015, 04:28:47 AM »
thanks I'll try it