using UnityEngine; // Use this Script in parent folder of all Humans public class SetDiamondMaterialTime : MonoBehaviour { [Header("Diamond Materials:")] public Material year2019; public Material year2020; public Material year2021; public Material default_mat; // Start is called before the first frame update void Start() { Component[] allChild = GetComponentsInChildren(); // all possible children of parent object foreach (Transform child in allChild) { //allChild[0] is parent if (child.parent == allChild[0]) { if(child.CompareTag("2021")) { child.Find("diamond1").GetComponent().material = year2021; } else if (child.CompareTag("2020")) { child.Find("diamond1").GetComponent().material = year2020; } else if (child.CompareTag("2019")) { child.Find("diamond1").GetComponent().material = year2019; } else { child.Find("diamond1").GetComponent().material = default_mat; } } } } }