void setSearchText() { Component[] components = GetComponentsInChildren <Component>(); foreach (Component c in components) { UnityEngine.UI.Text text = c.gameObject.GetComponent <UnityEngine.UI.Text>(); if (text && text.CompareTag("Filename")) { text.text = searchString; } } }