Can't change GameObject color via script?
Solution 1:
Here is your problem:
new Color(0f, 0f, 0f, **255f**);
The Color
constructor parameter takes values from 0f
to 1f
but you are passing 0f
to 255f
range value to it.
That should be:
colorToFadeTo = new Color(0f, 0f, 0f, 1f);
If you want to use the 0
to 255
range then you must divide it by 255
.
colorToFadeTo = new Color(0f, 0f, 0f, 255f/255f);
Also, there is Color32
which can take values between 0
and 255
. You can use that then covert it back to color.
Color32 color32 = new Color32(0f, 0f, 0f, 255f));
Color color = color32;