private void setTexts(string lastLap, string bestLap, string lapCount, string totalTime) { string[] texts = { car.name, lastLap, bestLap, lapCount, totalTime }; var t = timeListElement.transform; var count = System.Math.Min(texts.Length, t.childCount); for (var i = 0; i < count; i++) { var c = t.GetChild(i); c.GetComponent <TextMeshProUGUI>().text = texts[i]; } t.GetComponentInChildren <Image>().color = car.GetColor(); }