Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

How can I set minimum or maximum size using anchors?

Discussion in 'UGUI & TextMesh Pro' started by JYKeith, Aug 27, 2014.

  1. JYKeith

    JYKeith

    Joined:
    Aug 17, 2014
    Posts:
    12
    I'm new to unity. trying to use New 4.6 UI system.
    but I wonder how to set minimum size or maximum size of my panels or images while using the anchors system.
    I'm really satisfied with anchor system, it's so easy,,, but no such things support??
     
  2. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    567
    I'm not sure I undertand correctly, but if you mean a min/ max size in pixels, that would need to be done through script. You can then easily convert your numbers in pixels to relative anchor points by dividing that number by the screen width. For example:

    Code (csharp):
    1. int maxWidth = 400;
    2. float relWidth = maxWidth / Camera.main.pixelWidth;
    3. rectTransform.achorMax = new Vector2(rectTransform.anchorMin.x + relWidth, rectTransform.anchorMax.y);
     
    JYKeith likes this.