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 Adding gradient texture to UI image

Discussion in 'UGUI & TextMesh Pro' started by Artpen, Sep 11, 2021.

  1. Artpen

    Artpen

    Joined:
    Jan 24, 2015
    Posts:
    291
    Hey guys,
    Need your help. I made a pie graph using fill type UI image.
    And depending on how many data points I have I have the same number of coolers for each wedge.
    Screenshot 2021-09-11 at 14.13.09.png
    I can change the colors simply changing the color of the UI image, BUT I need some gradient.

    So I have created a shader (using shader graph) and it looks nice
    Screenshot 2021-09-11 at 14.12.18.png Screenshot 2021-09-11 at 14.11.11.png

    So the problem I have is that I have multiple wedges (and their number is dynamic) I need to find a way to change colours.
    And I don't want to create multiple materials.

    1. I tried MaterialPropertyBlocks, but it doesn't work on UI elements.
    2. I also tried using image with gradient, but the result is not as nice.

    Any Ideas or hacks ?