Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Change the color of a 2D sprite using a shader

Discussion in 'Shaders' started by AlexKostas, Aug 25, 2017.

  1. AlexKostas

    AlexKostas

    Joined:
    Apr 13, 2017
    Posts:
    15
    Hello all!

    I have a 2D spritesheet. I have included it below. By using this spritesheet I am making a life line animation. What I need is, when the player's health is under 25% the life line color will turn to orange.

    Of course, I tried to change the color in the inspector, but the existing color (light green) mixes with the new color (orange) and create a completely new one. And definetely I do not want that.

    So I think that the best way to solve this problem is to write a shader to turn the existing color to orange. Although, I have a big problem: I do not know how to write shaders. I tried to find some existing shaders in this Forum. I also tried to modify the standard shader, but none of the above worked.

    I know that for someone who knows about shading and shaders it is pretty easy. I tried everything and anything I know, I aksed some friends of mine for help. I did a lot of research in the internet, but what I achived is to get more confused.

    Can anyone here help me please???

    Thank you for taking time reading my post!

    Here is the spritesheet. Please note that it is transparent

    Health Line.png
     
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Just make your lifeline texture white instead of green. Then tint the image as you previously had.
     
  3. AlexKostas

    AlexKostas

    Joined:
    Apr 13, 2017
    Posts:
    15
    Hello! Thank you for your reply.
    The problem is that the image has different colors not only one. So I can not just make it white.
    Could you give me an alternative?
     
  4. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Make it greyscale then. Setting Image color will multiply on top and give you light/dark greens.