Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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

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

  1. mortoray


    Sep 14, 2018
    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.