public void PrintPlanetTemperatures() { for (int i = 0; i < planets.Length; i++) { // get the planet from the array Planet thePlanet = planets[i]; // does it have a thermostat Thermostat theThermostat = thePlanet.GetComponent <Thermostat>(); if (theThermostat == null) { // this planet does not have a thermostat Debug.Log(thePlanet.name + " does not have a thermostat. No temperature data available!"); } else { // this planet has a thermostat! Debug.Log("The temperature on " + thePlanet.name + " is:"); theThermostat.PrintTemperature(); } } }