Unity 遍历子节点找子对象

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MyReset : MonoBehaviour {
    public Material MyMat;

    private void Reset()
    {
        MyMat = Resources.Load("Shaders/ImageEffect_MaskIcon");
        foreach (Transform t in transform.GetComponentsInChildren())
        {
            if (t.name == "Display_Image")
            {
                t.GetComponent().material = MyMat;
                Debug.Log("true");
            }
        }
    }
}

 

你可能感兴趣的:(unity)