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

Question Create component like UI Image that respects the RectTransform size?

Discussion in 'UGUI & TextMesh Pro' started by mortoray, Feb 18, 2023.

  1. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    94
    How do I create a custom component that behaves like UI image, where the size of the image is based on the RectTransform's size?

    Right now I'm doing something simple with a SpriteRenderer to figure this out. In the UI Image, the size of the RectTransform changes the image size without modifying the scale. I want to do the same thing: I want my SpriteRenderer to somehow render at the size of the RectTransform.

    I'm thinking a child game object with a scale would work, and then some how I connect the size to the scale. I'm unsure about this, since it feels like it might be overkill, and also since I don't know how to respond to size changes.