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. Dismiss Notice

Question How to change UI Element width/height by C#

Discussion in 'UI Toolkit' started by mmbb2w4r6y8i, Aug 28, 2020.

  1. mmbb2w4r6y8i

    mmbb2w4r6y8i

    Joined:
    May 21, 2017
    Posts:
    2
    I know how to define all property of UI Element by USS and USML. But i want to auto fit rect to meet some conditions.Can you tell me how to do it by C#? Thanks a lot.
     
  2. chris-z562

    chris-z562

    Joined:
    Jul 11, 2012
    Posts:
    41
    Code (CSharp):
    1. IStyle style = visualElement.style;
    2. style.width = 5f;
    3. style.height = 10f;
    This is how I do it. Not sure if it's the correct way to do it though.
     
    MarcSpraragen likes this.
  3. mmbb2w4r6y8i

    mmbb2w4r6y8i

    Joined:
    May 21, 2017
    Posts:
    2
    I'll try it.Thank you very much!