Im trying to make a brightness slider for a game that mixes 2d sprites and 3d objects. Since lighting doesnt really affect the sprites, i want to be able to change their brightness through code. I noticed that changing the alpha value does absolutely nothing unless its set to 0 (unless you do it in the editor, then it seems to work). I also saw they made a RGBToHSV method, but its a getter not a setter. Is there any way to change a sprites Value/Brightness through code?
Answer by Salocin19
Mar 08 at 07:06 PM
In code, color values are "normalized." This means that values are <= 1 and >= 0.
In the unity editor, color values range from 0-255, for r,g,b and alpha.
If you wanted to set alpha to 127.5 (half of the max value) in code, then you would have to set alpha to 0.5.
Similarly, an alpha of 255 in editor = 1 in code and, an alpha of 0 in editor = 0 in code.
My guess is that, for example, if you wanted a sprite at half alpha, you attempted to set the alpha in code to 127.5. Since the values in the code are "normalized", anything above 1 will just have the alpha look like it's at its max value.
Hope this helps!
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
232 People are following this question.
Change sprite color on GameObjects from a list.
How to change color property of the Sprite Renderer in C#
Problem with a color randomization
Multiple Cars not working