在untiy3d中获取通过父游戏物体得到子游戏物体

来源:互联网 发布:网络集线器hub 编辑:程序博客网 时间:2024/06/15 04:41

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class FatherGameObject : MonoBehaviour 

{

//用来存储子游戏物体的transform组件

public static Transform[]  m_transform; 


//父游戏物体的transform组件

private Transform m_parentTransform; 


void Awake()

{

m_parentTransform = gameObject.GetComponent<Transform>();


m_transform  = new Transform[m_parentTransform.childCount]; 


for (int i = 0; i < m_transform.Lenght; i++)

{

m_transform[i]  = m_parentTransform.GetChild(i); 

}

}

}


1 0