Код выдаёт ошибку на строчке "Button[0].GetComponent<SpriteRenderer>().color = new Color32(200, 20, 10,25);"
NullReferenceException: Object reference not set an instance of an object
Код
public GameObject[] Button;
void Update()
{
if(PlayerPrefs.GetInt("Car1") == 1)
{
Button[0].GetComponent<SpriteRenderer>().color = new Color32(200, 20, 10,25);
}
else if(PlayerPrefs.GetInt("Car2") == 1)
{
Button[1].GetComponent<SpriteRenderer>().color = new Color32(200, 20, 10, 25);
}
else if (PlayerPrefs.GetInt("Car3") == 1)
{
Button[2].GetComponent<SpriteRenderer>().color = new Color32(200, 20, 10, 25);
}
}