public void OnModeToggle() { if (actualMode.Equals(DisplayMode.ENERGY)) { energyBar.SetActive(false); for (int y = 0; y < heightTotal; y++) { for (int x = 0; x < widthTotal; x++) { objects[y, x].GetComponent <Image>().color = actualColor[y, x]; } } actualMode = DisplayMode.STRUCTURE; } else if (actualMode.Equals(DisplayMode.STRUCTURE)) { int tempMaxEnergy = 1; energyBar.SetActive(true); // Looking for max energy to scale up for (int y = 0; y < heightTotal; y++) { for (int x = 0; x < widthTotal; x++) { if (objects[y, x].GetComponent <Grain>().energy > tempMaxEnergy) { tempMaxEnergy = objects[y, x].GetComponent <Grain>().energy; } } } maxValueText.text = tempMaxEnergy.ToString(); for (int y = 0; y < heightTotal; y++) { for (int x = 0; x < widthTotal; x++) { objects[y, x].GetComponent <Image>().color = ColorHandler.MapEnergyToColor(objects[y, x].GetComponent <Grain>().energy, tempMaxEnergy); } } actualMode = DisplayMode.ENERGY; } }