Sprite color is stuck after changing it in script
Hello guys, I've been working on an in-game shop for a 2D project and came across a confusing problem. I want to make the items that haven't been bought to be darker, while the rest to have their natural color. Here's the part of this script that does this:
private void CheckItems()
{
for (int i = 0; i < car_items_GO.Count; i++)
{
if (GM.playerHasCar(car_items[i].id))
{
car_items_GO[i].transform.Find("price_tag").gameObject.SetActive(false);
car_items_GO[i].transform.Find("value").gameObject.SetActive(true);
car_items_GO[i].transform.Find("car_image").GetComponent<Image>().color = new Vector4(1f, 1f, 1f, 1f);
car_items_GO[i].transform.Find("buy_button").GetComponent<Button>().interactable = false;
}
else
{
car_items_GO[i].transform.Find("price_tag").gameObject.SetActive(true);
car_items_GO[i].transform.Find("value").gameObject.SetActive(false);
car_items_GO[i].transform.Find("car_image").GetComponent<Image>().color = new Vector4(0.26f, 0.26f, 0.26f, 1f);
car_items_GO[i].transform.Find("buy_button").GetComponent<Button>().interactable = true;
}
}
}
However, once the colors are changed accordingly, they remain stuck for some reason. For example, calling the function again won't do anything, and I can't even change the colors in the Editor. I mean, I can change the values, but the color remain as it is, even though the color values remain as I change them, not as in the script, which makes me very confused. Disabling/enabling the Image also works. CheckItems() is not in any infinite cycle. What am I doing wrong?
Your answer
Follow this Question
Related Questions
Shift a Sprite's color palette? 0 Answers
Sprite Selection clutter 0 Answers
2D-Sprite Bug? 1 Answer
,2d gameObject unwanted outline 0 Answers