Changing Sprite Colour Through Code Not Working

Hello, I am trying to change my sprite’s colour through code, but it gives me either weird effects or does not change at all. My sprite is a white circle.

GetComponent<SpriteRenderer>().color = new Color(0, 180, 180);

The above code changes the color to (0, 191, 191), sometimes it does not even work at all, sometimes the color changes to white. The changes are seemingly random and unexpected. Using presets such as Color.blue or Color.red works perfectly fine, custom color codes don’t, what am I doing wrong? I am using the latest version of Unity

7552705--933802--Expected Shade.jpg
7552705--933805--Actual Shade.jpg

The range of UnityEngine.Color is 0-1 (and higher for HDR)
You can use values of 0-255 using the Color32 type though.

2 Likes

That fixed it, thank you!