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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Match the size of an image

Discussion in 'Scripting' started by LumoKvin, Mar 18, 2020.

  1. LumoKvin

    LumoKvin

    Joined:
    Sep 28, 2019
    Posts:
    195
    I have 2 images: SourceImage and TargetImage. I want the width of TargetImage to match the width of SourceImage.

    This is the RectTransform of the source image:
    Screen Shot 2020-03-17 at 1.10.36 PM (1).png

    I tried this but it sets the width to 0
    Screen Shot 2020-03-18 at 5.05.11 PM.png

    I also tried this but the size is wrong:
    Screen Shot 2020-03-18 at 5.05.25 PM.png

    How can I get the width of TargetImage to match the width of SourceImage?
     
  2. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    785
    Did you mean to get the RectTransform size or the Image size? If the latter, you should be getting the Image component.
    It looks like your rect is size 0?
     
  3. LumoKvin

    LumoKvin

    Joined:
    Sep 28, 2019
    Posts:
    195
    Yes. It is zero.

    I want to get the current size of the SourceImage related to the current screen resolution. The SourceImage changes size because of the screen size.