1. 程式人生 > >【Unity&DragonBones】如何使得骨架Armature下的物體透明

【Unity&DragonBones】如何使得骨架Armature下的物體透明

這個LayerTest.CS檔案不能和DragonBones一起使用

因為呼叫的是Transform變數

如果和DragonBones一起使用,using DragonBones;

就會顯示DragonBones的Transform變數與Unity的Transform變數錯誤

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

public class LayerTest : MonoBehaviour {

    // Use this for initialization
    void Start () {
        
        int i = 31;

        print("i==:" + i + "\n");
        foreach (Transform t in GetComponentsInChildren<Transform>())//遍歷此.CS檔案掛的物體下每個子物體
        {
          print("name:" + t.name + "\n");
            if (t.GetComponent<MeshRenderer>() != null)//判斷每個子物體是否有MeshRenderer元件
            {
                t.GetComponent<MeshRenderer>().enabled = false;//判斷每個子物體是否有MeshRenderer元件,如果有,使其透明
            }

           
        }
    }
}

如果LayerTest.CS檔案遍歷到這些物體,使其透明