Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    557
    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.