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

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.