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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Current image width?

Discussion in 'Scripting' started by turbosheep, Sep 18, 2015.

  1. turbosheep

    turbosheep

    Joined:
    Jul 19, 2013
    Posts:
    25
    I'm scaling an UI image while preserving its aspect ratio, sometimes causing the rect transform to outgrow the image size in width. I want another UI object, a green plain, to retain the width of the image with, not the rect transform width.

    In short, I need to get the image width. The scaled width, not the source image width.
    Any help would be appreciated... everything I have tried only gives the original width, not run-time scaled width.
     
  2. turbosheep

    turbosheep

    Joined:
    Jul 19, 2013
    Posts:
    25
    See attachment for what I mean. :)
     

    Attached Files:

  3. Craig8726

    Craig8726

    Joined:
    Jul 5, 2013
    Posts:
    79
    not exactly sure i understand what you are trying to do but try using rectTransform.sizeDelta for manipulating the size. it accounts for changing resloutions.