Find child object that Contains string from list
Hi!
I am trying to achieve following Player inputs text > text compared to List of children of an object > If child in list Contains input text > Change material of that child.
However, having a bunch of issues with this. Got it working if the exact term is entered, however I specifically need that all children that Contain input term are changed. Also, I would have a requirement that the search is case insensitive.
Code that I have attempted (no errors returned but it simply does not find any children).
public Material glowmat;
public Transform ImportedModel;
private Transform founditem;
var list = ImportedModel.GetComponentsInChildren<string>();
for (int i = 3; i < list.Length; i++)
if (list[i].Contains(text))
{
founditem = ImportedModel.transform.GetChild(i);
founditem.GetComponent<Renderer>().material = glowmat;
displaytext.text = founditem.ToString();
}
else
{
displaytext.text = "none";
}
Help is kindly appreciated!
Comment