I cannot seem to change the color of an Image now. First I thought it’s because I hadn’t assigned it a sprite, but after assigning it a sprite, it still didn’t work.
I took a look at the documentation of Color and it said it expects the value to be between 0f and 1f, so I changed it to that and it still didn’t work.
Looking at one of the answers in Unity Answers, someone said that using Color32 solves the problem. It didn’t. (Yes, I did put the RGBA values of Color32 between 0 and 255.)
Then I found a bug in Unity Issue Tracker that says it only happens if your image type is “Simple”, so I modified the sprite a bit and set the image size to “Sliced”. (which doesn’t give any warning/errors in the inspector/console)
It didn’t work.
I found another post in Unity Answers that said that it is because the sprite is black.
The sprite I made, however, was a completely white 1x1px square. (and I set the color in the inspector to be dark blue)
----- Additional info -----
- Yes, the inspector does modify the color of the image.
- No, the code doesn’t give an exception.
- Yes, I made sure the color values are in the expected range (0f to 1f for Color, 0 to 255 for Color32)
- No, the beginning color of the image wasn’t white, it was dark blue and I tried to change that color to white using a script.
- No, I didn’t accidentally drag and drop the wrong image.
- Unity version: 2020.2.1f1 Personal
- Windows OS: Windows 10 64-bit
- CPU: 4-core @ 3.5GHz
- RAM: 4GB
Can anyone help me?
Thanks in advance!
(The important part of the) code:
[SerializeField]
private Image targetImage;
public void Update() {
targetImage.color = Color.white;
}